Values and Types
Booleans and Null
Booleans represent true-or-false answers, while null marks a missing value.
Booleans and Null
booleans_null.php
<?php
$stock = ;
$hasStock = $stock > 0;
$label = null;
if ($hasStock) {
$label = "ready";
} else {
$label = "empty";
}
echo "stock=" . $stock . "\n";
echo "hasStock=" . ($hasStock ? "true" : "false") . "\n";
echo "label=" . $label . "\n";
<?php
$stock = ;
$hasStock = $stock > 0;
$label = null;
if ($hasStock) {
$label = "ready";
} else {
$label = "empty";
}
echo "stock=" . $stock . "\n";
echo "hasStock=" . ($hasStock ? "true" : "false") . "\n";
echo "label=" . $label . "\n";
<?php
$stock = ;
$hasStock = $stock > 0;
$label = null;
if ($hasStock) {
$label = "ready";
} else {
$label = "empty";
}
echo "stock=" . $stock . "\n";
echo "hasStock=" . ($hasStock ? "true" : "false") . "\n";
echo "label=" . $label . "\n";
null
`null` means a variable has no useful value yet.