PHP Tutorial (& MySQL) #10 – Booleans & Comparisons
In this tutorial, we’ll be looking at Booleans and comparisons in PHP.
Booleans
Booleans are simple values that can have one of two values: true or false. They are often used in conditional statements, such as if statements, to determine whether or not a certain condition is met.
Comparisons
Comparisons are used to compare two values and determine which is greater, lesser, or equal. The comparison operators are as follows:
== – equal
!= – not equal
> – greater than
< - lesser than >= – greater than or equal to
<= - lesser than or equal to The following examples demonstrate how to use comparisons: if ($a == $b) { echo "The two values are equal"; } if ($a > $b) {
echo “The value of $a is greater than the value of $b”;
}
if ($a <= $b) { echo "The value of $a is less than or equal to the value of $b"; }