我应该使用empty()php函数吗 [英] should i use empty() php function
本文介绍了我应该使用empty()php函数吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
哪个更好?
if (!empty($val)) { // do something }
和
if ($val) { // do something }
当我使用PHP 5进行测试时,所有情况下都会产生相同的结果.那么PHP 4呢,还是知道哪种方法更好?
when i test it with PHP 5, all cases produce the same results. what about PHP 4, or have any idea which way is better?
推荐答案
您应使用 empty()
等效于!isset($var) || $var == false
.如果变量为:
empty()
is the equivalent of !isset($var) || $var == false
. It returns true if the variable is:
-
""
(空字符串) -
0
(0为整数) -
0.0
(浮点数为0) -
"0"
(0作为字符串) -
NULL
-
FALSE
-
array()
(一个空数组) -
var $var;
(已声明变量,但类中没有值)
""
(an empty string)0
(0 as an integer)0.0
(0 as a float)"0"
(0 as a string)NULL
FALSE
array()
(an empty array)var $var;
(a variable declared, but without a value in a class)
这篇关于我应该使用empty()php函数吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文