Skip to content

Instantly share code, notes, and snippets.

@1000k
Created April 18, 2012 07:32
Show Gist options
  • Save 1000k/2411752 to your computer and use it in GitHub Desktop.
Save 1000k/2411752 to your computer and use it in GitHub Desktop.
various way to check whether the value is set
<?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