Why check both isset() and !empty()

后端 未结 10 2512
难免孤独
难免孤独 2020-11-21 23:48

Is there a difference between isset and !empty. If I do this double boolean check, is it correct this way or redundant? and is there a shorter way

10条回答
  •  天涯浪人
    2020-11-22 00:05

    Empty just check is the refered variable/array has an value if you check the php doc(empty) you'll see this things are considered emtpy

    * "" (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)
    

    while isset check if the variable isset and not null which can also be found in the php doc(isset)

提交回复
热议问题