Booleans in PHP7
A Boolean value will return TRUE or FALSE. If an integer is zero 0 it is considered FALSE in PHP7. If a string has nothing in it then it is considered FALSE in PHP7. Negative numbers are considered TRUE to Boolean. Here are some examples.
Integer Boolean False
<?php $var=0; var_dump((bool) $var); ?>
Result would be: bool(false).
Integer Boolean True
Notice we are using a negative 2 “-2”. Even though it is negative number it is still TRUE to Boolean.
<?php $var=-2; var_dump((bool) $var); ?>
Result would be: bool(true)
String Boolean False
<?php $var=""; var_dump((bool) $var); ?>
Result would be: bool(false).
How We Would Use Booleans
We use booleans in PHP to see if something is true or false. So if we need to see if a variable has a value or not we can use the var_dump((bool) $var); to see if there is anything in it or not.
Here are the complete files for this lesson.
A1WEBSITEPRO Social Media Pages
Here are my social media pages, lets hook up!