Logical Values in PHP
Besides numbers and strings, there is another data type -
boolean. It consists of only two possible values:
true or false. These values
denote truth and falsehood respectively.
The boolean data type is used for things that
suggest two possible answers - yes or no. For example, to the question
"are you already 18 years old?" you can answer
yes, which is true, or no, which is
false.
Let's look at an example:
<?php
$isAdult = true; // already an adult
?>
Let's change the value to another:
<?php
$isAdult = false; // not an adult yet
?>
Let's output the value of our variable to the screen.
We'll use the special function
var_dump for this:
<?php
$isAdult = true;
var_dump($isAdult); // will output true
?>
However, it is not convenient to output boolean
values via echo:
<?php
echo true; // will output 1
echo false; // will output nothing
?>
Assign the value true to a variable.
Output this variable to the screen.
Assign the value false to a variable.
Output this variable to the screen.