7) PHP Operators

Operator supported by PHP:

  • Arithmetic operators.
  • Assignment operators.
  • Comparison operators.
  • Increment/Decrement operators.
  • Logical operators.
  • String operators.
  • Array operators.

Arithmetic Operator:

Operator Meaning Operator Meaning
-$a Negation $a/$b Division
$a+$b Addition $a%$b Modulus
$a-$b Subtraction $a**$b Exponentiation
$a*$b Multiplication
  • “-” Is used for both negation and subtraction. + for addition. * for multiplication and / for a division.
  • “%” is used for modulus operator used to find the remainder in division.
  • ** is exponentiation operator. Value on the left to the power value in right.

Example:

Logical Operators:

 

Operator Example Meaning
&& $a && $b True if both $a and $b are true
|| $a || $b True if either $a or $b is true
! !$a Reverse meaning of $a