TRUE | FALSE | 1 | 0 | -1 | "1" | "0" | "-1" | NULL | array() | array(1) | "php" | "" |
---|
true | false | true | false | true | true | false | true | false | false | true | true | false |
== | TRUE | FALSE | 1 | 0 | -1 | "1" | "0" | "-1" | NULL | array() | array(1) | "php" | "" |
---|
TRUE | true | false | true | false | true | true | false | true | false | false | true | true | false |
---|
FALSE | false | true | false | true | false | false | true | false | true | true | false | false | true |
---|
1 | true | false | true | false | false | true | false | false | false | false | false | false | false |
---|
0 | false | true | false | true | false | false | true | false | true | false | false | true | true |
---|
-1 | true | false | false | false | true | false | false | true | false | false | false | false | false |
---|
"1" | true | false | true | false | false | true | false | false | false | false | false | false | false |
---|
"0" | false | true | false | true | false | false | true | false | false | false | false | false | false |
---|
"-1" | true | false | false | false | true | false | false | true | false | false | false | false | false |
---|
NULL | false | true | false | true | false | false | false | false | true | true | false | false | true |
---|
array() | false | true | false | false | false | false | false | false | true | true | false | false | false |
---|
array(1) | true | false | false | false | false | false | false | false | false | false | true | false | false |
---|
"php" | true | false | false | true | false | false | false | false | false | false | false | true | false |
---|
"" | false | true | false | true | false | false | false | false | true | false | false | false | true |
---|
=== | TRUE | FALSE | 1 | 0 | -1 | "1" | "0" | "-1" | NULL | array() | array(1) | "php" | "" |
---|
TRUE | true | false | false | false | false | false | false | false | false | false | false | false | false |
---|
FALSE | false | true | false | false | false | false | false | false | false | false | false | false | false |
---|
1 | false | false | true | false | false | false | false | false | false | false | false | false | false |
---|
0 | false | false | false | true | false | false | false | false | false | false | false | false | false |
---|
-1 | false | false | false | false | true | false | false | false | false | false | false | false | false |
---|
"1" | false | false | false | false | false | true | false | false | false | false | false | false | false |
---|
"0" | false | false | false | false | false | false | true | false | false | false | false | false | false |
---|
"-1" | false | false | false | false | false | false | false | true | false | false | false | false | false |
---|
NULL | false | false | false | false | false | false | false | false | true | false | false | false | false |
---|
array() | false | false | false | false | false | false | false | false | false | true | false | false | false |
---|
array(1) | false | false | false | false | false | false | false | false | false | false | true | false | false |
---|
"php" | false | false | false | false | false | false | false | false | false | false | false | true | false |
---|
"" | false | false | false | false | false | false | false | false | false | false | false | false | true |
---|
<?php // Ůńïčøđē
header('Content-Type: text/html; charset=UTF-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<title>PHP boolean</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo ini_get('default_charset'); ?>" />
<style type="text/css">
<!--
table
{
border-collapse: collapse;
margin-bottom: 10px;
}
table, td, th
{
border: 1px solid #000;
}
td, th
{
padding: 2px;
text-align : center;
}
.true
{
color: Navy;
}
.false
{
color: FireBrick;
}
-->
</style>
</head>
<body>
<?php
$arr_str_expression = array('TRUE', 'FALSE', '1', '0', '-1', '"1"', '"0"', '"-1"', 'NULL', 'array()', 'array(1)', '"php"', '""');
// boolean cast
echo '<table><tr>';
foreach ($arr_str_expression as $str_col)
{
echo "<th>$str_col</th>";
}
echo '</tr><tr>';
foreach ($arr_str_expression as $str_col)
{
eval("\$bool_equal = !!($str_col);");
$str_result = str_replace('placeholder', ($bool_equal) ? 'true' : 'false', '<span class="placeholder">'.var_export($bool_equal, 1).'</span>');
echo "<td>$str_result</td>";
}
echo '</tr></table>';
// ==
echo '<table><tr><th>==</th>';
foreach ($arr_str_expression as $str_col)
{
echo "<th>$str_col</th>";
}
echo '</tr>';
foreach ($arr_str_expression as $str_row)
{
echo "<tr><th>$str_row</th>";
foreach ($arr_str_expression as $str_col)
{
eval("\$bool_equal = ($str_row == $str_col);");
$str_result = str_replace('placeholder', ($bool_equal) ? 'true' : 'false', '<span class="placeholder">'.var_export($bool_equal, 1).'</span>');
echo "<td>$str_result</td>";
}
echo '</tr>';
}
echo '</table>';
// ===
echo '<table><tr><th>===</th>';
foreach ($arr_str_expression as $str_col)
{
echo "<th>$str_col</th>";
}
echo '</tr>';
foreach ($arr_str_expression as $str_row)
{
echo "<tr><th>$str_row</th>";
foreach ($arr_str_expression as $str_col)
{
eval("\$bool_equal = ($str_row === $str_col);");
$str_result = str_replace('placeholder', ($bool_equal) ? 'true' : 'false', '<span class="placeholder">'.var_export($bool_equal, 1).'</span>');
echo "<td>$str_result</td>";
}
echo '</tr>';
}
echo '</table>';
echo '<hr />';
highlight_file(__FILE__);
?>
</body>
</html>