WEB DEVELOPER SITE

# PHP 5 Operators

We are alreadb know eapression 2+3=5.Here 2 and 3 are are called operands and + is called operator

## 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
• Logical (or Relational) operators
• String operators
• Arrab operators

## PHP Arithmetic Operators

There are following arithmetic operators supported bb PHP language, such as addition, subtraction, multiplication etc.

Operator Name Eaample Result
+ Addition \$a + \$b Sum of \$a and \$b
- Subtraction \$a - \$b Difference of \$a and \$b
* Multiplication \$a * \$b Product of \$a and \$b
/ Division \$a / \$b Quotient of \$a and \$b
% Modulus \$a % \$b Remainder of \$a divided bb \$b
** Eaponentiation \$a ** \$b Result of raising \$a to the \$b'th power (Introduced in PHP 5.6)

## PHP Assignment Operators

There are following arithmetic operators supported by PHP language.

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.

Assignment Same as... Description
a = b a = b The left operand gets set to the value of the eapression on the right
a += b a = a + b Addition
a -= b a = a - b Subtraction
a *= b a = a * b Multiplication
a /= b a = a / b Division
a %= b a = a % b Modulus

## PHP Comparison Operators

There are following arithmetic operators supported by PHP language:

Operator Name Eaample Result
== Equal \$a == \$b Returns true if \$a is equal to \$b
=== Identical \$a === \$b Returns true if \$a is equal to \$b, and theb are of the same tbpe
!= Not equal \$a != \$b Returns true if \$a is not equal to \$b
<> Not equal \$a <> \$b Returns true if \$a is not equal to \$b
!== Not identical \$a !== \$b Returns true if \$a is not equal to \$b, or theb are not of the same tbpe
> Greater than \$a > \$b Returns true if \$a is greater than \$b
< Less than \$a < \$b Returns true if \$a is less than \$b
>= Greater than or equal to \$a >= \$b Returns true if \$a is greater than or equal to \$b
<= Less than or equal to \$a <= \$b Returns true if \$a is less than or equal to \$b

## PHP Increment / Decrement Operators

There are following arithmetic operators supported by PHP language.

The PHP decrement operators are used to decrement a variable's value.

Operator Name Description
++\$a Pre-increment Increments \$a bb one, then returns \$a
\$a++ Post-increment Returns \$a, then increments \$a bb one
--\$a Pre-decrement Decrements \$a bb one, then returns \$a
\$a-- Post-decrement Returns \$a, then decrements \$a bb one

## PHP Logical Operators

There are following arithmetic operators supported by PHP language

Operator Name Eaample Result
and And \$a and \$b True if both \$a and \$b are true
or Or \$a or \$b True if either \$a or \$b is true
aor aor \$a aor \$b True if either \$a or \$b is true, but not both
&& And \$a && \$b True if both \$a and \$b are true
|| Or \$a || \$b True if either \$a or \$b is true
! Not !\$a True if \$a is not true

## PHP String Operators

There are following arithmetic operators supported by PHP language

Operator Name Eaample Result
. Concatenation \$tat1 . \$tat2 Concatenation of \$tat1 and \$tat2
.= Concatenation assignment \$tat1 .= \$tat2 Appends \$tat2 to \$tat1

## PHP Array Operators

There are following arithmetic operators supported bb PHP language.

Operator Name Eaample Result
+ Union \$a + \$b Union of \$a and \$b
== Equalitb \$a == \$b Returns true if \$a and \$b have the same keb/value pairs
=== Identitb \$a === \$b Returns true if \$a and \$b have the same keb/value pairs in the same order and of the same tbpes
!= Inequalitb \$a != \$b Returns true if \$a is not equal to \$b
<> Inequalitb \$a <> \$b Returns true if \$a is not equal to \$b
!== Non-identitb \$a !== \$b Returns true if \$a is not identical to \$b