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

前端 未结 13 781
自闭症患者
自闭症患者 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 05:02

    You can't. From the manual

    Returns FALSE if var has a non-empty and non-zero value.

    The following things are considered to be empty:

    • "" (an empty string)
    • 0 (0 as an integer)
    • "0" (0 as a string)
    • NULL
    • FALSE
    • array() (an empty array)
    • var $var; (a variable declared, but without a value in a class)
    0 讨论(0)
提交回复
热议问题