10-29-2017, 11:54 AM
1

Operators are used to perform operations on variables and values.

PHP divides the operators in the following groups:

PHP Arithmetic Operators

+ (Addition) Example : $x + $y Sum of $x and $y

- (Subtraction) Example : $x - $y Difference of $x and $y

* (Multiplication) Example : $x * $y Product of $x and $y

/ (Division) Example : $x / $y Quotient of $x and $y

% (Modulus) Example : $x % $y Remainder of $x divided by $y

** (Exponentiation) Example : $x ** $y Result of raising $x to the $y'th power (Introduced in PHP 5.6)

PHP Assignment Operators

x = y The left operand gets set to the value of the expression on the right

x += y (Same as x = x + y) Addition

x -= y (Same as x = x - y ) Subtraction

x *= y (Same as x = x * y ) Multiplication

x /= y (Same as x = x / y) Division

x %= y (Same as x = x % y) Modulus

PHP Comparison Operators

== (Equal) Example : $x == $y Returns true if $x is equal to $y

=== (Identical) Example : $x === $y Returns true if $x is equal to $y, and they are of the same type

!= (Not equal) Example : $x != $y Returns true if $x is not equal to $y

<> (Not equal) Example : $x <> $y Returns true if $x is not equal to $y

!== (Not identical) Example : $x !== $y Returns true if $x is not equal to $y, or they are not of the same type

> (Greater than) Example : $x > $y Returns true if $x is greater than $y

< (Less than) Example : $x < $y Returns true if $x is less than $y

>= (Greater than or equal to) Example : $x >= $y Returns true if $x is greater than or equal to $y

<= (Less than or equal to) Example : $x <= $y Returns true if $x is less than or equal to $y

PHP Increment / Decrement Operators

++$x (Pre-increment) Increments $x by one, then returns $x

$x++ (Post-increment) Returns $x, then increments $x by one

--$x (Pre-decremen) Decrements $x by one, then returns $x

$x-- (Post-decrement) Returns $x, then decrements $x by one

PHP Logical Operators

and (And) Example : $x and $y True if both $x and $y are true

or (Or) Example : $x or $y True if either $x or $y is true

xor (Xor) Example : $x xor $y True if either $x or $y is true, but not both

&& (And) Example : $x && $y True if both $x and $y are true

|| (Or ) Example : $x || $y True if either $x or $y is true

! (Not) Example : !$x True if $x is not true

PHP String Operators

. (Concatenation) Example : $txt1 . $txt2 Concatenation of $txt1 and $txt2

.= (Concatenation assignment) Example : $txt1 .= $txt2 Appends $txt2 to $txt1

PHP Array Operators

+ (Union) Example : $x + $y Union of $x and $y

== (Equality) Example : $x == $y Returns true if $x and $y have the same key/value pairs

=== (Identity) Example : $x === $y Returns true if $x and $y have the same key/value pairs in the same order and of the same types

!= (Inequality) Example : $x != $y Returns true if $x is not equal to $y

<> (Inequality) Example : $x <> $y Returns true if $x is not equal to $y

!== (Non-identity) Example : $x !== $y Returns true if $x is not identical to $y

PHP divides the operators in the following groups:

- Arithmetic operators

- Assignment operators

- Comparison operators

- Increment/Decrement operators

- Logical operators

- String operators

- Array operators

PHP Arithmetic Operators

+ (Addition) Example : $x + $y Sum of $x and $y

- (Subtraction) Example : $x - $y Difference of $x and $y

* (Multiplication) Example : $x * $y Product of $x and $y

/ (Division) Example : $x / $y Quotient of $x and $y

% (Modulus) Example : $x % $y Remainder of $x divided by $y

** (Exponentiation) Example : $x ** $y Result of raising $x to the $y'th power (Introduced in PHP 5.6)

PHP Assignment Operators

x = y The left operand gets set to the value of the expression on the right

x += y (Same as x = x + y) Addition

x -= y (Same as x = x - y ) Subtraction

x *= y (Same as x = x * y ) Multiplication

x /= y (Same as x = x / y) Division

x %= y (Same as x = x % y) Modulus

PHP Comparison Operators

== (Equal) Example : $x == $y Returns true if $x is equal to $y

=== (Identical) Example : $x === $y Returns true if $x is equal to $y, and they are of the same type

!= (Not equal) Example : $x != $y Returns true if $x is not equal to $y

<> (Not equal) Example : $x <> $y Returns true if $x is not equal to $y

!== (Not identical) Example : $x !== $y Returns true if $x is not equal to $y, or they are not of the same type

> (Greater than) Example : $x > $y Returns true if $x is greater than $y

< (Less than) Example : $x < $y Returns true if $x is less than $y

>= (Greater than or equal to) Example : $x >= $y Returns true if $x is greater than or equal to $y

<= (Less than or equal to) Example : $x <= $y Returns true if $x is less than or equal to $y

PHP Increment / Decrement Operators

++$x (Pre-increment) Increments $x by one, then returns $x

$x++ (Post-increment) Returns $x, then increments $x by one

--$x (Pre-decremen) Decrements $x by one, then returns $x

$x-- (Post-decrement) Returns $x, then decrements $x by one

PHP Logical Operators

and (And) Example : $x and $y True if both $x and $y are true

or (Or) Example : $x or $y True if either $x or $y is true

xor (Xor) Example : $x xor $y True if either $x or $y is true, but not both

&& (And) Example : $x && $y True if both $x and $y are true

|| (Or ) Example : $x || $y True if either $x or $y is true

! (Not) Example : !$x True if $x is not true

PHP String Operators

. (Concatenation) Example : $txt1 . $txt2 Concatenation of $txt1 and $txt2

.= (Concatenation assignment) Example : $txt1 .= $txt2 Appends $txt2 to $txt1

PHP Array Operators

+ (Union) Example : $x + $y Union of $x and $y

== (Equality) Example : $x == $y Returns true if $x and $y have the same key/value pairs

=== (Identity) Example : $x === $y Returns true if $x and $y have the same key/value pairs in the same order and of the same types

!= (Inequality) Example : $x != $y Returns true if $x is not equal to $y

<> (Inequality) Example : $x <> $y Returns true if $x is not equal to $y

!== (Non-identity) Example : $x !== $y Returns true if $x is not identical to $y