PHP Operators Tutorial

PHP operators are used to performing some specific operation on variables and values.

What are PHP Operators?

PHP Operators operand one or more than one Operand.

These operators supported by PHP language.

-Assignment Operators

-Arithmetic Operators

-Comparison Operators

-Conditional / Ternary Operators

-Logical / Relational Operators

### Assignment Operators

These are assignment operators which are supported by PHP language

Suppose \$a = 30 and \$b = 10

### Arithmetic Operators

These are arithmetic operators which are supported by PHP language

Suppose \$a = 30 and \$b = 10

 Operators Name Description Example + Addition Addition of two operands \$a + \$b  //output : 40 - Subtraction Subtract of two operands \$a - \$b  //output : 20 * Multiplication Multiplication of two operands \$a * \$b  //output : 300 / Devide Devide numerator by de-numerator \$a / \$b  //output : 3 % Modulas Remainder of after an integer division \$a % \$b  //output : 0 -- Decrement Decrease integer value by one \$a--     //output : 29 ++ Increament Increase integer value by one \$a++     //output : 31

### Comparison Operators

These are comparison operators which are supported by PHP language

Suppose \$a = 30 and \$b = 10

 Operators Name Description Example == Equal Compare left operand equal to right \$a == \$b  //output : false === Identical Compare left operand equal to right and both are the same type \$a === \$b //output : false != Not equal Compare left operand not equal to right \$a != \$b  //output : false !== Not identical Compare left operand not equal to right and both are not the same type \$a !== \$b //output : false > Greater than Compare left operand is greater than right \$a > \$b   //output : true < Less than Compare left operand is less than right \$a < \$b   //output : false >= Greater than or equal to Compare left operand is greater than or equal to right \$a >= \$b  //output : true <= Less than or equal to Compare left operand is less than or equal to right \$a <= \$b  //output : false

### Conditional / Ternary Operators

These are comparison operators which are supported by PHP language

Suppose \$a = 30 and \$b = 10

 Operator Name Description Example ? : Ternary If condition true then first value print otherwise second echo (\$a == \$b ? \$a : \$b); //output : 10

### Logical / Relational Operators

These are logical/relational operators which are supported by PHP language

Suppose \$a = 35 and \$b = 0

 Operators Name Description Example && Logical AND If both operands are not zero then condition become true (\$a && \$b)   //output : false || Logical OR If one operand of them are not zero then condition become true (\$a || \$b)   //output : true ! Logical NOT If condition is true then logical not reverse the condition and make it false !(\$a && \$b)  //output : true

Find us on 