Derfder
Derfder

Reputation: 3324

If statement with condition isset and comparing not working together

I'm having a problems with making if statements:

<?php if (isset($detail) == 1) { ?>
    // code if detail variable exists and is equal to 1
<?php } else { ?>
    // code if detail variable doesn't exist or is not equal 1
<?php }?>

For some reason this condition doesn't work. How could I fix the if condition, so it will work?

Upvotes: 0

Views: 3159

Answers (1)

Kermit
Kermit

Reputation: 34053

isset is a boolean operator which returns TRUE or FALSE. You don't need to compare it to 1.

if( isset($detail) )

As a side note, just because the variable is set, does not mean it's not empty. You may want to just check that it's not empty:

if( !empty($detail) )

Upvotes: 2

Related Questions