if($val) vs. if($val != “”) vs. if(!empty($val)) — which one?

后端 未结 6 594
暗喜
暗喜 2020-12-09 20:39

I see a lot of people using a variety of different methods to check whether of a variable is empty, there really seems to be no consensus. I\'ve heard that if($foo)

6条回答
  •  萌比男神i
    2020-12-09 20:59

    empty($foo) should return true in all of these cases: 0,"", NULL.

    For a more complete list check this page: http://php.net/manual/en/function.empty.php

提交回复
热议问题