Slide 1
Most trusted JOB oriented professional program
DevOps Certified Professional (DCP)

Take your first step into the world of DevOps with this course, which will help you to learn about the methodologies and tools used to develop, deploy, and operate high-quality software.

Slide 2
DevOps to DevSecOps – Learn the evolution
DevSecOps Certified Professional (DSOCP)

Learn to automate security into a fast-paced DevOps environment using various open-source tools and scripts.

Slide 2
Get certified in the new tech skill to rule the industry
Site Reliability Engineering (SRE) Certified Professional

A method of measuring and achieving reliability through engineering and operations work – developed by Google to manage services.

Slide 2
Master the art of DevOps
Master in DevOps Engineering (MDE)

Get enrolled for the most advanced and only course in the WORLD which can make you an expert and proficient Architect in DevOps, DevSecOps and Site Reliability Engineering (SRE) principles together.

Slide 2
Gain expertise and certified yourself
Azure DevOps Solutions Expert

Learn about the DevOps services available on Azure and how you can use them to make your workflow more efficient.

Slide 3
Learn and get certified
AWS Certified DevOps Professional

Learn about the DevOps services offered by AWS and how you can use them to make your workflow more efficient.

previous arrow
next arrow

What are the Operators in PHP?

Spread the Knowledge

What is Operators in PHP ?

Operators are symbols that tell the PHP processor to perform certain actions. For example, the addition (+) symbol is an operator that tells PHP to add two variables or values, while the greater-than (>) symbol is an operator that tells PHP to compare two values.

The following lists describe the different operators used in PHP.

PHP Arithmetic Operators

Arithmetic operators are used to performing common arithmetical operations, such as addition, subtraction, multiplication, etc. Here’s a complete list of PHP’s arithmetic operators:

OperatorDescriptionExampleResult
+Addition$x + $ySum of $x and $y
Subtraction$x – $yDifference of $x and $y.
*Multiplication$x * $yProduct of $x and $y.
/Division$x / $yQuotient of $x and $y
%Modulus$x % $yRemainder of $x divided by $y

The following example will show you these arithmetic operators in action:

Example:

PHP Assignment Operators

The assignment operators are used to assign values to variables.

OperatorDescriptionExampleIs The Same As
=Assign$x = $y$x = $y
+=Add and assign$x += $y$x = $x + $y
-=Subtract and assign$x -= $y$x = $x – $y.
*=Multiply and assign$x *= $y$x = $x * $y
/=Divide and assign quotient$x /= $y$x = $x / $y
%=Divide and assign modulus$x %= $y$x = $x % $y

The following example will show you these assignment operators in action:

Example:-

PHP Comparison Operators

The comparison operators are used to compare two values in a Boolean fashion.

OperatorDescriptionExampleResult
==Equal$x == $yTrue if $x is equal to $y
===Identical$x === $yTrue if $x is equal to $y, and they are of the same type
!=Not equal$x != $yTrue if $x is not equal to $y
<>Not equal$x <> $yTrue if $x is not equal to $y
!==Not identical$x !== $yTrue if $x is not equal to $y, or they are not of the same type
<Less than$x < $yTrue if $x is less than $y
>Greater than$x > $yTrue if $x is greater than $y
>=Greater than or equal to$x >= $yTrue if $x is greater than or equal to $y
<=Less than or equal to$x <= $yTrue if $x is less than or equal to $y

The following example will show you these comparison operators in action:

Example:-

PHP Incrementing and Decrementing Operators

The increment/decrement operators are used to increment/decrement a variable’s value.

OperatorNameEffect
++$xPre-incrementIncrements $x by one, then returns $x
$x++Post-incrementReturns $x, then increments $x by one
–$xPre-decrementDecrements $x by one then returns $x
$x–Post-decrementReturns $x, then decrements $x by one

The following example will show you these increment and decrement operators in action:

Example:-

PHP Logical Operators

The logical operators are typically used to combine conditional statements.

OperatorNameExampleResult
andAnd$x and $yTrue if both $x and $y are true
orOr$x or $yTrue if either $x or $y is true
xorXor$x xor $yTrue if either $x or $y is true, but not both
&&And$x && $yTrue if both $x and $y are true
||Or$x || $yTrue if either $$x or $y is true
!Not!$xTrue if $x is not true

The following example will show you these logical operators in action:

Example=>

PHP String Operators

There are two operators which are specifically designed for strings.

OperatorDescriptionExampleResult
.Concatenation$str1 . $str2 Concatenation of $str1 and $str2
.=Concatenation assignment$str1 .= $str2Appends the $str2 to the $str1

The following example will show you these string operators in action:

Example=>

PHP Array Operators

The array operators are used to compare arrays:

True if $x is not equal to $yOperatorNameExampleResult
+Union$x + $yUnion of $x and $y
==Equality$x == $yTrue if $x and $y have the same key/value pairs
===Identity$x === $yTrue if $x and $y have the same key/value pairs in the same order and of the same types
!=Inequality$x != $y True if $x is not equal to $y
<>Inequality$x <> $yTrue if $x is not equal to $y
!==Non-identity$x !== $yTrue if $x is not identical to $y

The following example will show you these array operators in action:

Example=>

PHP Spaceship Operator

The spaceship operator returns 0 if both operands are equal, 1 if the left is greater, and -1 if the right is greater. It basically provides three-way comparison as shown in the following table:

Operator<=> Equivalent
$x < $y($x <=> $y) === -1
$x <= $y($x <=> $y) === -1 || ($x <=> $y) === 0
$x == $y($x <=> $y) === 0
$x != $y($x <=> $y) !== 0
$x >= $y($x <=> $y) === 1 || ($x <=> $y) === 0
$x > $y$x <=> $y) === 1

The following example will show you how spaceship operator actually works:

Example=>

Facebook Notice for EU! You need to login to view and post FB Comments!
Dharmendra K
Latest posts by Dharmendra K (see all)