[PHP] empty()、is_null()、isset() 區別
http://php.net/manual/en/types.comparisons.php
http://www.blueshoes.org/en/developer/php_cheat_sheet/ (此圖的出處)
http://overapi.com/php/ (列表)
Note: empty() and isSet() don't give a warning when the variable has not been defined before
http://www.blueshoes.org/en/developer/php_cheat_sheet/ (此圖的出處)
http://overapi.com/php/ (列表)
Empty() is_null() isSet()
gettype() | empty() | is_null() | isSet() | (bool) | |
$x = ""; | string | true | false | true | false |
$x = null; | NULL | true | true | false | false |
var $x; (not set) | NULL | true | true | false | false |
$x = array(); | array | true | false | true | false |
$x = false; | boolean | true | false | true | false |
$x = 15; | integer | false | false | true | true |
$x = 1; | integer | false | false | true | true |
$x = 0; | integer | true | false | true | false |
$x = -1; | integer | false | false | true | true |
$x = "15"; | string | false | false | true | true |
$x = "1"; | string | false | false | true | true |
$x = "0"; | string | true | false | true | false |
$x = "-1"; | string | false | false | true | true |
$x = "foo"; | string | false | false | true | true |
$x = "true"; | string | false | false | true | true |
$x = "false"; | string | false | false | true | true |
Note: empty() and isSet() don't give a warning when the variable has not been defined before
留言
張貼留言