2016-09-16 17 views
1

empty()falsy-nessテストとbool型キャストとの間に違いはありますか?空

は、次のような場合にfalsyネスを検出:

"" (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) 

はbool型キャストでFalseに変換され、その他の値はありますか?

+1

質問は何ですか?理解できない –

+0

PHP Docsのリストが間違っていると思いますか? –

+0

あなたは本当に何を望んでいるのか、あなたの本当の質問は何ですか? –

答えて

0

@Bertは、ページ上のテーブルから派生

を示唆したように答えはhttp://php.net/manual/en/types.comparisons.phpにある:empty()if(!$x)が等価であることを示唆している

+-----------------------+---------+------------------+-------------------+ 
|      |   |     |     | 
+-----------------------+---------+------------------+-------------------+ 
| 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    | 
+-----------------------+---------+------------------+-------------------+