devnotes.

Arithmetic, Assignment, and Comparison Operators

Arithmetic operators:

$a + $b;   // addition
$a - $b;   // subtraction
$a * $b;   // multiplication
$a / $b;   // division
$a % $b;   // modulus (remainder)
$a ** $b;  // exponentiation ($a to the power of $b)

Assignment operators combine an operation with assignment:

$a += 5;   // same as $a = $a + 5
$a -= 3;   $a *= 2;   $a /= 4;   $a .= '!'; // string concatenation-assign

Comparison operators:

$a == $b;    // equal (value only, loose)
$a === $b;   // identical (value AND type, strict — prefer this)
$a != $b;    // not equal
$a !== $b;   // not identical
$a < $b; $a > $b; $a <= $b; $a >= $b;
$a <=> $b;   // spaceship operator: -1, 0, or 1 — great for sort callbacks

Increment/decrement: $a++, $a--, ++$a, --$a — the prefix versions change the value before it's used in an expression, the postfix versions after.

The null coalescing operator ?? returns the left operand if it's set and not null, otherwise the right: $name = $input ?? 'Guest';. Its assignment form ??= is also common: $config['timeout'] ??= 30;.

PHP Arithmetic, Assignment & Comparison Operators | DevNotes