Last active
July 27, 2017 01:37
-
-
Save syamgot/f5cd0e8cbef77e927777942ad261d0d3 to your computer and use it in GitHub Desktop.
[PHP]issetとarray_key_existsの違い
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arr = ['NULL' => NULL,'ゼロ' => 0, '空文字' => '']; | |
// | |
echo "isset : \n"; | |
foreach($arr as $key => $val) { | |
echo $key.'は' | |
. ( isset($arr[$key]) ? 'TRUE' : 'FALSE' ) | |
. "\n"; | |
} | |
echo "\n"; | |
echo "array_key_exists : \n"; | |
foreach($arr as $key => $val) { | |
echo $key.'は' | |
. ( array_key_exists($key, $arr) ? 'TRUE' : 'FALSE' ) | |
. "\n"; | |
} | |
/* **************************************** | |
isset : | |
NULLはFALSE | |
ゼロはTRUE | |
空文字はTRUE | |
array_key_exists : | |
NULLはTRUE | |
ゼロはTRUE | |
空文字はTRUE | |
issetは変数が存在してかつNULLではないかの判定なので | |
キーが存在するかしないかはarray_key_existsを使う | |
**************************************** */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment