Check if value isset and null

前端 未结 8 454
迷失自我
迷失自我 2020-11-30 01:26

I need to check if value is defined as anything, including null. isset treats null values as undefined and returns false. Take the following as an

8条回答
  •  借酒劲吻你
    2020-11-30 02:10

    is_null($bar) returns true, since it has no values at all. Alternatively, you can use:

    if(isset($bar) && is_null($bar)) // returns false
    

    to check if $bar is defined and will only return true if:

    $bar = null;
    if(isset($bar) && is_null($bar)) // returns true
    

提交回复
热议问题