Logical Operators

Some of these will be useful now. Some will be used later when I start explaining control structures such as if statements, however here are the operators available to you in PHP

$a += $b same as $a = $a + $b // plus
$a -= $b same as $a = $a - $b // minus
$a *= $b same as $a = $a * $b // multiply
$a /= $b same as $a = $a / $b // divide
$a .= $b same as $a = $a . $b // concatenate (for use in strings)
$a++ same as $a = $a + 1
$a-- same as $a = $a - 1
$a == $b // comparison operator, used in if statements etc.
$a = $b // assignment operator, ie. $a becomes the value of $b - don't get this and the comparison operator mixed up!
$a != $b // not equal to
$a < $b // $a is less than $b
$a <= $b // $a is less than or equal to $b
$a > $b // $a is greater than $b
$a >= $b // $a is great than or equal to $b
!$a // NOT operator, returns true if $a is false
$a && $b // AND operator, returns true if both are true
$a || $b // OR operator, returns true if either are true
$a AND $b // same as AND operator
$a OR $b // same as OR operator

You may also like...