WEB DEVELOPER SITE

# PHP 5 operators

In this section we will discuss the application of different operators in PHP.

In PHP, the assignment operator = is used to assign values to variables.

In PHP, the arithmetic operator + is used to add values together.

## 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

The following table lists the operators in order of priority. Operators in the same line have the same priority, and their combination direction determines the evaluation order.

Explanation : left = left to right, right = right to left.

Assignment Same as... Description
a = b a = b The left operand gets set to the estimation 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

The comparison operator lets you compare two values:

operator name description example
x == y equal If x is equal to y, return true 5 == 8 return false
x === y Absolutely equal If x is equal to y and they are of the same type, return true 5 === "5" return false
x! = y Not equal If x is not equal to y, thenreturn true 5!=8 return true
x <> y Not equal If x is not equal to y, then return true 5<>8 return true
x !== y Absolutely not equal If x is not equal to y, or their types are not the same, then return true 5!=="5" return true
x > y greater than If x is greater than y, then return true 5>8 return false
x < y less than If x is less than y, return true 5<8 return true
x >= y greater than or equal to If x is greater than or equal to y, then return true 5>=8 return false
x <= y less than or equal If x is less than or equal to y, return true 5<=8 return true

## PHP Increment/Decrement Operators

The PHP decrement administrators are utilized to decrement a variable's value.

operator name description
++ x Pre-increment x plus 1, then return x
x ++ Post-increment Return x, then x plus 1
-x Pre-decrement x minus 1, then returns x
x- Decrement after Return x, then x minus 1

## PHP Logical Operators

operator name description example
x and y and If both x and y are true, return true x=6
y=3
(x < 10 and y > 1) return true
x or y or true if at least one of x and y is true x = 6
y = 3
(x == 6 or y == 5) returns true
x xor y Exclusive OR true if only one of x and y is true x = 6
y = 3
(x == 6 xor y == 3) returns false
x && y With If both x and y are true, return true x=6
y=3
(x < 10 && y > 1) Returns true
x || y or true if at least one of x and y is true x = 6
y = 3
(x == 5 || y == 5) returns false
! x Not true if x is not true x = 6
y = 3
! (x == y) returns true

## PHP String Operators

There are following number juggling administrators bolstered 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

operator name description
x + y Collection set of x and y
x == y Equal true if x and y have the same key /value pair
x === y Identities Returns true if x and y have the same key /value pair and the same order and type.
x! = y Not equal true if x is not equal to y
x <> y Not equal true if x is not equal to y
x! == y Inequality If x is not equal to y, return true