问题
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?
回答1:
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) )
来源:https://stackoverflow.com/questions/15669075/if-statement-with-condition-isset-and-comparing-not-working-together