function and_test($x, $y)
{
$z = ($x && $y) ? "true" : "false"; // True if $x and $y are true
return $x . " and " . $y . " = " . $z . "<br />";
}
echo and_test(1, 1);
echo and_test(1, 0);
echo and_test(0, 1);
echo and_test(0, 0);
// if ($x && $y)
echo "<br />";
function or_test($x, $y)
{
$z = ($x || $y) ? "true" : "false"; // True if $x or $y is true
return $x . " or " . $y . " = " . $z . "<br />";
}
echo or_test(1, 1);
echo or_test(1, 0);
echo or_test(0, 1);
echo or_test(0, 0);
// if ($x || $y)
echo "<br />";
function xor_test($x, $y)
{
$z = ($x xor $y) ? "true" : "false"; // True if $x or $y is true, but not both
return $x . " xor " . $y . " = " . $z . "<br />";
}
echo xor_test(1, 1);
echo xor_test(1, 0);
echo xor_test(0, 1);
echo xor_test(0, 0);
// if ($x xor $y)
echo "<br />";
function not_test($x)
{
$z = (!$x) ? "true" : "false"; // True if $x is false
return "!" . $x . " = " . $z . "<br />";
}
echo not_test(1);
echo not_test(0);
// if (!$x)
/*
run:
1 and 1 = true
1 and 0 = false
0 and 1 = false
0 and 0 = false
1 or 1 = true
1 or 0 = true
0 or 1 = true
0 or 0 = false
1 xor 1 = false
1 xor 0 = true
0 xor 1 = true
0 xor 0 = false
!1 = false
!0 = true
*/