If statement with condition isset and comparing not working together

社会主义新天地 提交于 2020-01-21 10:23:41

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!