Why check both isset() and !empty()

后端 未结 10 2525
难免孤独
难免孤独 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:18

    $a = 0;
    if (isset($a)) { //$a is set because it has some value ,eg:0
        echo '$a has value';
    }
    if (!empty($a)) { //$a is empty because it has value 0
        echo '$a is not empty';
    } else {
        echo '$a is empty';
    }
    

提交回复
热议问题