PHP Operators

|

Operators are used to manipulate or perform operations on variables and values. There are many operators used in PHP, we

have separated them into the following categories.


# Assignment Operators

# Arithmetic Operators

# Comparison Operators

# Logical Operators


Assignment operators are used to set a variable equal to a value or set a variable to another variable's value. ‘=’ is


used for assignment operator.
Example:


$var = 23;

$var2 = $var;



OperatorExampleIs The Same As
=a=ba=b
+=a+=ba=a+b
-=a-=ba=a-b
*=a*=ba=a*b
/=a/=ba=a/b
.= a.=ba=a.b
%=a%=ba=a%b



Arithmetic Operators:


OperatorFunction
+Addition
-Subtraction
*Multiplication
/Division
%Modulus (division remainder)
++Increment
--Decrement



OperatorFunction ExampleResult
== Equal To$x == $yfalse
!= Not Equal To$x != $ytrue
< Less Than$x < $y true
>Greater Than$x > $y false
<= Less Than or Equal To$x <= $y true
>= Greater Than or Equal To$x >= $y false


Logical Operators:



OperatorFunctionExample
&&andx=8 y=4
(x <> 1) returns true
||or x=12
y=8
(x>=5 || y<=5) returns true
!notx=6
y=3
!(x==y) returns true