What are the operators of php?

PHP Operators

Operators are used to perform operations on variables and values.

PHP divides the operators in the following groups:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Increment/Decrement operators
  • Logical operators
  • String operators
  • Array operators
  • Conditional assignment operators

PHP Arithmetic Operators

The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

OperatorNameExampleResultShow it
+ Addition $x + $y Sum of $x and $y Try it »
- Subtraction $x - $y Difference of $x and $y Try it »
* Multiplication $x * $y Product of $x and $y Try it »
/ Division $x / $y Quotient of $x and $y Try it »
% Modulus $x % $y Remainder of $x divided by $y Try it »
** Exponentiation $x ** $y Result of raising $x to the $y'th power Try it »

PHP Assignment Operators

The PHP assignment operators are used with numeric values to write a value to a variable.

The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.

AssignmentSame as... DescriptionShow it
x = y x = y The left operand gets set to the value of the expression on the right Try it »
x += y x = x + y Addition Try it »
x -= y x = x - y Subtraction Try it »
x *= y x = x * y Multiplication Try it »
x /= y x = x / y Division Try it »
x %= y x = x % y Modulus Try it »

PHP Comparison Operators

The PHP comparison operators are used to compare two values [number or string]:

OperatorNameExampleResultShow it
== Equal $x == $y Returns true if $x is equal to $y Try it »
=== Identical $x === $y Returns true if $x is equal to $y, and they are of the same type Try it »
!= Not equal $x != $y Returns true if $x is not equal to $y Try it »
Not equal $x $y Returns true if $x is not equal to $y Try it »
!== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the same type Try it »
> Greater than $x > $y Returns true if $x is greater than $y Try it »
< Less than $x < $y Returns true if $x is less than $y Try it »
>= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y Try it »

Chủ Đề