PHP Operators

PHP Operators

The Arithmatic Operators:

ExampleNameResult
$n + $zAdditionSum of $n and $z.
$n – $zSubtractionDifference of $n and $z.
$n * $zMultiplicationProduct of $n and $z.
$n / $zDivisionQuotient of $n and $z.
$n % $zModulusRemainder of $n divided by $z.
$n ** $zExponentiationResult of raising $n to the $z power. Introduced in PHP 5.6.

The Assignment Operators:

AssignmentSame asResult
$n = $z$n = $zn get the value of z.
$n += $z$n = $n + $zAddition
$n -= $z$n = $n – $zSubtraction
$n *= $z$n = $n * $zMultiplication
$n /= $z$n = $n / $zDivision
$n %= $z$n = $n % $zModulus

Comparison Operators:

ExampleNameResult
$n == $zEqualReturns true if $n is equal to $z
$n === $zIdenticalReturns true if $n is equal to $z, and they are of the same type.
$n != $zNot equalReturns true if $n is not equal to $z
$n <> $zNot equalReturns true if $n is not equal to $z
$n !== $zNot identicalReturns true if $n is not equal to $z
$n < $zLess thanReturns true if $n is less than $z
$n > $zGreater thanReturns true if $n is greater than $z
$n <= $zLess than or equal toReturns true if $n is less than or equal to $z.
$n => $zGreater than or equal toReturns true if $n is greater than or equal to $z.

Increment/decrement Operators:

ExampleNameResult
++$iPre-incrementIncrements $i by one, then returns $i
$i++Post-incrementReturns $i, then increments $i by one
–$iPre-decrementDecrements $i by one, then returns $i
$i–Post-decrementReturns $i, then decrements $i by one

Logical Operators:

ExampleNameResult
$i and $jAndReturns true if both $i and $j are true.
$i or $jOrReturns true if either $i or $j is true.
$i xor $jXorReturns true if either $i or $j is true, but not both.
! $iNotReturns true if $i is not true.
$i && $jAndReturn true if both $i and $j are true.
$i || $jOrReturns true if either $i or $j is true.

String Operators:

ExampleNameResult
$a . $bConcatenationConcatenation of $a and $b
$a .= $bConcatenation assignmentAppends $a to $b

Array Operators:

ExampleNameResult
$i + $jUnionUnion of $i and $j.
$i == $jEqualityReturns true if $i and $j have the same key/value pairs.
$i === $jIdentityReturns true if $i and $j have the same key/value pairs in the sameorder and of the same types.
$i != $jInequalityReturns true if $i is not equal to $j.
$i <> $jInequalityReturns true if $i is not equal to $j.
$i !== $jNon-identityReturns true if $i is not identical to $j.