PHP Operator

Facebooktwitterredditpinterestlinkedinmailby feather

PHP Operator is used to perform operations on variable and values.

Following are the types of Operator:

PHP Arithmetic Operator

PHP Arithmetic operator is used for arithmetical operations, such as addition, subtraction, multiplication etc.

 +Addition$x + $y
 –Subtraction$x – $y
 *Multiplication$x * $y
/Division$x / $y
 %Modulus$x %$y
**Exponentiation$x ** $y

PHP Assignment Operators

PHP assignment operator is used to write a value to a variable.

x=y , x=yThe yvalueassign to X value$x=$y
x+=y , x=x+yAddition$x=$y+$z
x-=y , x=x-ySubtraction$x=$y-$z
x*=y , x=x*yMultiplication$x=$y+$z
x/=y , x=x/yDivision$x=$y/$z
x%=y, x=x%yModulus$x=$y%$z

PHP Comparison Operators

PHP comparison operator are used to compare two values (number and string)

==Equal$x == $y
===Identical$x === $y
!=Not equal$x != $y
<>Not equal$x <> $y
!==Not identical$x !== $y
>Greater than$x > $y
<Less than$x < $y
>=Greater than or equal to$x >= $y
<=Less than or equal to$x <= $y

PHP Increment / Decrement Operators

PHP increment and decrement operator is used to increment and decrement a variable’s value.

++$xPre-incrementIt Increments $x by 1, then returns $x.
$x++Post-incrementIt returns $x, then increments $x by 1.
–$xPre-decrementIt decrements $x by 1, then returns $x.
$x–Post-decrementIt returns $x, then decrements $x by one.

PHP Logical Operators

The PHP Operators are used to merge two or more conditional statements.

andAndTrue if both $x and $y are true.
orOrTrue if either $x or $y is true.
xorXorTrue if either $x or $y is true, but not both.
&&AndTrue if both $x and $y are true.
||OrTrue if either $x or $y is true.
!NotTrue if $x is not true.

PHP String Operators

PHP string operators are used for string concatenation.

Following are the String Operators

.Concatenation$txt1 . $txt2
.=Concatenation assignment$txt1 .= $txt2

PHP Array Operators

PHP array operator is used to compare arrays.

+Union$x + $yIt is union of $x and $y.
==Equality$x == $yIt returns true if $x and $y have the same key/value.
===Identity$x === $yIt returns true if $x and $y have the same key/value pairs in the same order and of the same types.
!=Inequality$x != $yIt returns true if $x is not equal to $y.
<>Inequality$x <> $yIt returns true if $x is not equal to $y.
!==Non-identity$x !== $yIt returns true if $x is not identical to $y.
Facebooktwitterredditpinterestlinkedinmailby feather

Leave a Comment