php: '0' as a string with empty()

前端 未结 13 828
自闭症患者
自闭症患者 2020-12-06 04:05

I want a 0 to be considered as an integer and a \'0\' to be considered as a string but empty() considers the \'0\' as a string in the example below,

$var = \         


        
13条回答
  •  渐次进展
    2020-12-06 04:54

    I always add to my codebase

    function is_blank($value) {
        return empty($value) && !is_numeric($value);
    }
    

    and use it instead of empty(). It solves the issue of keeping zeros (int, float or string) as non-empty.

    See http://www.php.net/manual/en/function.empty.php#103756 which was added May 2011.

提交回复
热议问题