Created
April 18, 2012 07:32
-
-
Save 1000k/2411752 to your computer and use it in GitHub Desktop.
various way to check whether the value is set
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 | |
$subjects = array( | |
null, | |
true, | |
false, | |
"false", // 文字列の false | |
"", // 空文字列 | |
0, // integer の 0 | |
"0", // string の 0 | |
"aaaaa", // 任意のstring | |
12345, // 任意のinteger | |
array(), // 空の配列 | |
); | |
foreach ($subjects as $subject) { | |
$subject_str = str_replace("\n", '', var_export($subject, true)); | |
echo "*** {$subject_str} ***"; | |
echo "\nisset({$subject_str}): "; | |
echo isset($subject) ? 'true' : 'false'; | |
echo "\n!empty({$subject_str}): "; | |
echo !empty($subject) ? 'true' : 'false'; | |
echo "\n({$subject_str}): "; | |
echo ($subject) ? 'true' : 'false'; | |
echo "\n\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment