PHP Operators

Operators in PHP are essential tools for performing operations on variables and values. They make it possible to calculate, compare, assign, or manipulate data. These operators are divided into distinct groups to cater to specific functions.

Tutorials dojo strip



Categories of PHP Operators

  1. Arithmetic Operators
  2. Assignment Operators
  3. Comparison Operators
  4. Increment/Decrement Operators
  5. Logical Operators
  6. String Operators
  7. Array Operators
  8. Conditional Assignment Operators




PHP Arithmetic Operators

Arithmetic operators allow you to perform mathematical calculations.

OperatorNameExampleResult
+Addition$yamaha + $hondaSum of $yamaha and $honda
-Subtraction$yamaha - $hondaDifference between $yamaha and $honda
*Multiplication$yamaha * $hondaProduct of $yamaha and $honda
/Division$yamaha / $hondaQuotient of $yamaha divided by $honda
%Modulus$yamaha % $hondaRemainder of $yamaha divided by $honda
**Exponentiation$yamaha ** $honda$yamaha raised to the power of $honda




PHP Assignment Operators

These operators assign values to variables. The = operator is the simplest form of assignment.

OperatorSame as…Description
=$bmw = $audiAssigns the value of $audi to $bmw
+=$bmw += $audiAdds $audi to $bmw and assigns the result to $bmw
-=$bmw -= $audiSubtracts $audi from $bmw and assigns the result to $bmw
*=$bmw *= $audiMultiplies $bmw by $audi and assigns the result to $bmw
/=$bmw /= $audiDivides $bmw by $audi and assigns the quotient to $bmw
%=$bmw %= $audiAssigns the remainder of $bmw divided by $audi




PHP Comparison Operators

Comparison operators compare values, either numeric or string.

OperatorNameExampleResult
==Equal$nike == $pumatrue if $nike equals $puma
===Identical$nike === $pumatrue if $nike equals $puma and are of the same type
!=Not Equal$nike != $pumatrue if $nike is not equal to $puma
<>Not Equal$nike <> $pumatrue if $nike is not equal to $puma
!==Not Identical$nike !== $pumatrue if $nike is not equal to $puma or not the same type
>Greater Than$nike > $pumatrue if $nike is greater than $puma
<Less Than$nike < $pumatrue if $nike is less than $puma




PHP Increment/Decrement Operators

Increment/Decrement operators adjust a variable’s value by one.

OperatorDescriptionExample
++$adidasPre-incrementIncrement $adidas by 1, then return $adidas
$adidas++Post-incrementReturn $adidas, then increment it by 1
--$adidasPre-decrementDecrement $adidas by 1, then return $adidas
$adidas--Post-decrementReturn $adidas, then decrement it by 1




PHP Logical Operators

Logical operators combine multiple conditional statements.

OperatorNameExampleResult
andAnd$toyota and $nissantrue if both $toyota and $nissan are true
orOr$toyota or $nissantrue if at least one is true
!Not!$toyotatrue if $toyota is false




PHP String Operators

String operators are used for manipulating strings.

OperatorNameExampleResult
.Concatenation$brand1 . $brand2Combines $brand1 and $brand2 into a single string
.=Concatenation Assignment$brand1 .= $brand2Appends $brand2 to $brand1




PHP Array Operators

Array operators allow comparisons between arrays or their combination.

OperatorNameExampleResult
+Union$toyota + $hondaCombines arrays $toyota and $honda, keeping unique keys
==Equality$toyota == $hondaReturns true if $toyota and $honda have the same key-value pairs
===Identity$toyota === $hondaReturns true if $toyota and $honda are identical in type and order
!=Inequality$toyota != $hondaReturns true if $toyota is not equal to $honda
<>Inequality$toyota <> $hondaReturns true if $toyota is not equal to $honda
!==Non-identity$toyota !== $hondaReturns true if $toyota and $honda are not identical in type or order




PHP Conditional Assignment Operators

These operators allow assignment based on conditions.

OperatorNameExampleResult
?:Ternary$bmw = ($audi > 10) ? $audi : $toyotaIf $audi > 10, assigns $audi to $bmw; otherwise assigns $toyota
??Null Coalescing$bmw = $audi ?? $toyotaAssigns $audi to $bmw if $audi exists and is not NULL; otherwise assigns $toyota

Tutorials dojo strip
Scroll to Top