带有isset条件的If语句和比较语句不能一起工作


If statement with condition isset and comparing not working together

我在制作if声明时遇到了问题:

<?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 }?>

由于某些原因,这个条件不起作用。我如何修复if条件,使其工作?

isset是一个布尔运算符,返回TRUEFALSE。你不需要将它与1进行比较。

if( isset($detail) )
作为旁注,仅仅因为设置了变量,并不意味着它不是空的。您可能只想检查它是否为空:
if( !empty($detail) )