PHP Operators Explanation

by Hiroshi on June 19, 2008

in Operators

In all programming languages, operators are used to manipulate or perform operations on variables and values. There are many operators used in PHP.

  • Assignment Operators
  • Arithmetic Operators
  • Comparison Operators
  • String Operators
  • Combination Arithmetic & Assignment Operators

Assignment Operators

Assignment operators are used to set a variable equal to a value or set a variable to another variable’s value. Such an assignment of value is done with the “=”, or equal character. Example:

$myvar = 4;

Arithmetic Operators

Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
Modulus (%)

Comparison Operators

Equal To (==)
Not Equal To (!=)
Less Than (<) Greater Than (>)
Less Than or Equal To (<=) Greater Than or Equal To (>=)

Operators

! a
NOT
True if a is not true.

a && b
AND
True if both a and b are true.

a || b
OR
True if either a or b is true.

a and b
AND
True if both a and b are true.

a xor b
XOR
True if a or b is true, but not both.

a or b
OR
True if either a or b is true.

Conditional Operators in PHP

==
Is equal to

===
Is identical to (is equal and is the same data type)

!=
Is not equal to

!==
Is not identical to

<
Is less than

<=
Is less than or equal to

>
Is greater than

>=
Is greater than or equal to

Related Posts

Previous post:

Next post: