Reputation: 15494
Just a simple php question, i have this:
if(isset($_GET['i'])) { if($_GET['i']=='dash') {
It is possible to use one IF? Thanks!
Upvotes: 0
Views: 343
Reputation: 145482
You can alternatively use array_intersect_assoc
to check both conditions at once:
if (array_intersect_assoc($_GET, array("i" => "dash"))) {
Upvotes: 1
Reputation: 6771
I do it this way:
function initGet($var, $default=''){
if(!isset($_GET[$var])) return $default;
return $_GET[$var];
}
So you can check it easy:
if(initGet('i')=='dash'){
And you could add a default value if needed:
if(initGet('i', 'dash')=='dash'){
// would be true if $_GET['i'] is not set
Upvotes: 2
Reputation: 49208
Use a logical operator.
if (isset($_GET['i']) && $_GET['i'] == 'dash') {
This will test that both conditions return true
in the test.
Upvotes: 5