Difference between `if (isset($_SESSION))` and `if ($_SESSION)`?

前端 未结 3 2033
小蘑菇
小蘑菇 2021-01-18 02:11

I\'ve noticed that frequently people simply write


while I have been using:



        
3条回答
  •  温柔的废话
    2021-01-18 02:25

    say you set a variable = to false...

    $variable = false;
    

    This will not return anything, because it is making sure that the variable is not null, false or empty('')...

    if($variable){
        echo'something';
    }
    

    This will work regardless of what we set the variable to, as long as we set it... It can be false, str, int, anything except null!

    if(isset($variable)){
        echo'something';
    }
    

提交回复
热议问题