PHP Operators


 

PHP Operators

Operators are used for performing specific tasks. The operators in PHP are same like other programming languages like Arithmetic operators, Assignment Operators, Comparison Operators, and logical operators.

Operators are used for performing specific tasks. The operators in PHP are same like other programming languages like Arithmetic operators, Assignment Operators, Comparison Operators, and logical operators.

3.5. PHP Operators

Operators are used for performing specific tasks. The operators in PHP are same like other programming languages like Arithmetic operators, Assignment Operators, Comparison Operators, and logical operators.

3.5.1. Arithmetic Operators

These operators work similar to basic Mathematics functions.


Example

Name

Result

$a + $b

Addition

Sum of $a and $b.

$a - $b

Subtraction

Difference of $a and $b.

$a * $b

Multiplication

Product of $a and $b.

$a / $b

Division

Quotient of $a and $b.

$a % $b

Modulus

Remainder of $a divided by $b.

3.5.2. Logical Operators

Like other programming language, in PHP too, logical operators are used to compare elements, but the syntax is different like:


Example

Name

Result

$a and $b

And

TRUE if both $a and $b are TRUE.

$a or $b

Or

TRUE if either $a or $b is TRUE.

0

$a xor $b

Xor

TRUE if either $a or $b is TRUE, but not both.

1

 ! $a

Not

TRUE if $a is not TRUE.

2

$a && $b

And

TRUE if both $a and $b are TRUE.

3

$a || $b

Or

TRUE if either $a or $b is TRUE.

4

3.5.3. Comparison Operators

These give you the ability to compare whether elements are equal, identical, less than or greater than one another (with some other variations).


Example

Name

Result

5

$a == $b

Equal

TRUE if $a is equal to $b.

6

$a === $b

Identical

TRUE if $a is equal to $b, and they are of the same type. (PHP 4 only)

7

$a != $b

Not equal

TRUE if $a is not equal to $b.

8

$a <> $b

Not equal

TRUE if $a is not equal to $b.

9

$a !== $b

Not identical

TRUE if $a is not equal to $b, or they are not of the same type. (PHP 4 only)

0

$a < $b

Less than

TRUE if $a is strictly less than $b.

1

$a > $b

Greater than

TRUE if $a is strictly greater than $b.

2

$a <= $b

Less than or equal to

TRUE if $a is less than or equal to $b.

3

$a >= $b

Greater than or equal to

TRUE if $a is greater than or equal to $b.

4

Ads