Php 空时($var)!=((bool)$var==false)?
empty()错误测试和bool类型转换之间有什么区别吗 在以下情况下,empty会检测错误:Php 空时($var)!=((bool)$var==false)?,php,Php,empty()错误测试和bool类型转换之间有什么区别吗 在以下情况下,empty会检测错误: "" (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; (a variable declared, but without a value) 在布尔类型转换中是否有其他值被转换为False?答案在于@Bert所建议
"" (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; (a variable declared, but without a value)
在布尔类型转换中是否有其他值被转换为False?答案在于@Bert所建议的
根据页面上的表格得出:
+-----------------------+---------+------------------+-------------------+
| | | | |
+-----------------------+---------+------------------+-------------------+
| Expression | empty() | boolean : if($x) | boolean : if(!$x) |
| $x = ""; | TRUE | FALSE | TRUE |
| $x = null; | TRUE | FALSE | TRUE |
| var $x; | TRUE | FALSE | TRUE |
| $x is undefined | TRUE | FALSE | TRUE |
| $x = array(); | TRUE | FALSE | TRUE |
| $x = array('a', 'b'); | FALSE | TRUE | FALSE |
| $x = false; | TRUE | FALSE | TRUE |
| $x = true; | FALSE | TRUE | FALSE |
| $x = 1; | FALSE | TRUE | FALSE |
| $x = 42; | FALSE | TRUE | FALSE |
| $x = 0; | TRUE | FALSE | TRUE |
| $x = -1; | FALSE | TRUE | FALSE |
| $x = "1"; | FALSE | TRUE | FALSE |
| $x = "0"; | TRUE | FALSE | TRUE |
| $x = "-1"; | FALSE | TRUE | FALSE |
| $x = "php"; | FALSE | TRUE | FALSE |
| $x = "true"; | FALSE | TRUE | FALSE |
| $x = "false"; | FALSE | TRUE | FALSE |
+-----------------------+---------+------------------+-------------------+
这表明empty()
和if(!$x)
是等价的。答案就如@Bert所建议的那样
根据页面上的表格得出:
+-----------------------+---------+------------------+-------------------+
| | | | |
+-----------------------+---------+------------------+-------------------+
| Expression | empty() | boolean : if($x) | boolean : if(!$x) |
| $x = ""; | TRUE | FALSE | TRUE |
| $x = null; | TRUE | FALSE | TRUE |
| var $x; | TRUE | FALSE | TRUE |
| $x is undefined | TRUE | FALSE | TRUE |
| $x = array(); | TRUE | FALSE | TRUE |
| $x = array('a', 'b'); | FALSE | TRUE | FALSE |
| $x = false; | TRUE | FALSE | TRUE |
| $x = true; | FALSE | TRUE | FALSE |
| $x = 1; | FALSE | TRUE | FALSE |
| $x = 42; | FALSE | TRUE | FALSE |
| $x = 0; | TRUE | FALSE | TRUE |
| $x = -1; | FALSE | TRUE | FALSE |
| $x = "1"; | FALSE | TRUE | FALSE |
| $x = "0"; | TRUE | FALSE | TRUE |
| $x = "-1"; | FALSE | TRUE | FALSE |
| $x = "php"; | FALSE | TRUE | FALSE |
| $x = "true"; | FALSE | TRUE | FALSE |
| $x = "false"; | FALSE | TRUE | FALSE |
+-----------------------+---------+------------------+-------------------+
这表明
empty()
和if(!$x)
是等价的。问题是什么?不可理解你认为PHP文档中的列表是错误的吗?请正确描述你想要什么或你真正的问题是什么?谢谢Bert,这正是我想要的问题是什么?不可理解你认为PHP文档中的列表是错误的吗?请正确描述你想要什么或你真正的问题是什么?谢谢伯特,这正是我想要的