Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 空时($var)!=((bool)$var==false)?_Php - Fatal编程技术网

Php 空时($var)!=((bool)$var==false)?

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所建议

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所建议的

根据页面上的表格得出:

+-----------------------+---------+------------------+-------------------+
|                       |         |                  |                   |
+-----------------------+---------+------------------+-------------------+
| 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文档中的列表是错误的吗?请正确描述你想要什么或你真正的问题是什么?谢谢伯特,这正是我想要的