PHP Operators

PHP Operators

Arithmetic Operators:

+ , – , * , / , % , ++ and –

 

For / the result is always double

For % the operands must be integers else they are coerced to integers

 

Assignment Operators:

+=  and /=

 

Predefined functions on numeric values

floor()

ceil()

round()

rand()          two parameters

abs()

min()           one or more parameters

max()           one or more parameters

 

The other predefined functions are used for computing exponents, logarithms, trigonometric functions.

 

Relational Operators

PHP has eight relational operators

== , != , <, <=, > , >=.

===    is true only if both the operands are the same type and have same value

!==     is exactly opposite to ===

 

If the type of the operands of the relational operator are not same then coercion occurs.

if the string is compared with numbers, and if string can be converted to number then numeric comparison will be performed. If the string cannot be converted to number then the number operand is converted to a string and string comparison will be performed.

Boolean Operators:

PHP has six Boolean operators:

and , or , xor , ! , && and ||

 

The and and && will perform the same operation as well as or and || will also perform the same operation. The only difference between them is the precedence.