You are on page 1of 3

The assignment operator = is used to assign values to variables in PHP. The arithmetic operator + is used to add values together.

Arithmetic Operators
The table below lists the arithmetic operators in PHP: Operator x+y x-y x*y x/y x%y Name Addition Subtraction Multiplication Division Modulus Description Sum of x and y Difference of x and y Product of x and y Quotient of x and y Remainder of x divided by y Example 2+2 5-2 5*2 15 / 5 5%2 10 % 8 10 % 2 -2 "Hi" . "Ha" HiHa Result 4 3 10 3 1 2 0

-x a.b

Negation Concatenation

Opposite of x Concatenate two strings

Assignment Operators
The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the expression on the right. That is, the value of "$x = 5" is 5. Assignment Same as... x=y x += y x -= y x *= y x /= y x %= y a .= b x=y x=x+y x=x-y x=x*y x=x/y x=x%y a=a.b Description The left operand gets set to the value of the expression on the right Addition Subtraction Multiplication Division Modulus Concatenate two strings

Incrementing/Decrementing Operators
Operator ++ x x ++ -- x x -Name Pre-increment Post-increment Pre-decrement Post-decrement Description Increments x by one, then returns x Returns x, then increments x by one Decrements x by one, then returns x Returns x, then decrements x by one

Comparison Operators
Comparison operators allows you to compare two values: Operator x == y x === y x != y x <> y x !== y x>y x<y x >= y x <= y Name Equal Identical Not equal Not equal Not identical Greater than Less than Greater than or equal to Less than or equal to Description True if x is equal to y True if x is equal to y, and they are of same type True if x is not equal to y True if x is not equal to y Example 5==8 returns false 5==="5" returns false 5!=8 returns true 5<>8 returns true

True if x is not equal to y, or they are 5!=="5" returns true not of same type True if x is greater than y True if x is less than y 5>8 returns false 5<8 returns true

True if x is greater than or equal to y 5>=8 returns false True if x is less than or equal to y 5<=8 returns true

Logical Operators
Operator x and y Name And Description True if both x and y are true Example x=6 y=3 (x < 10 and y > 1) returns true

x or y

Or

True if either or both x and y are true x=6 y=3 (x==6 or y==5) returns true True if either x or y is true, but not both x=6 y=3 (x==6 xor y==3) returns false x=6 y=3 (x < 10 && y > 1) returns true

x xor y

Xor

x && y

And

True if both x and y are true

x || y

Or

True if either or both x and y are true x=6 y=3 (x==5 || y==5) returns false True if x is not true x=6 y=3 !(x==y) returns true

!x

Not

Array Operators
Operator x+y x == y x === y x != y Name Union Equality Identity Inequality Description Union of x and y True if x and y have the same key/value pairs True if x and y have the same key/value pairs in the same order and of the same types True if x is not equal to y

x <> y x !== y

Inequality Non-identity

True if x is not equal to y True if x is not identical to y

You might also like