Check if value isset and null

前端 未结 8 489
迷失自我
迷失自我 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:06

    See Best way to test for a variable's existence in PHP; isset() is clearly broken

     if( array_key_exists('foo', $GLOBALS) && is_null($foo)) // true & true => true
     if( array_key_exists('bar', $GLOBALS) && is_null($bar)) // false &  => false
    

提交回复
热议问题