Categories
PHP

PHP: Expressions and Operators

Arithmetic Operators:

+ Addition Add two values
– Subtraction Subtract the second value from the first
* Multiplication Multiply two values
/ Division Divide the first value by the second
% Modulus Divide the first value by the second and return only the remainder
(for example, 7 % 5 yields 2)

Comparison Operators:

= = Equal Checks for equal values
= = = Identical Checks for equal values and data types
! = Not Equal Checks for values not equal
! = = Not Identical Checks for values not equal or not the same data type
< Less than Checks for one value being less than the second
> Greater than Checks for one value being greater than the second
< = Less than or Equal to Checks for on value being less than or equal to the second
> = Greater than or Equal to Checks for on value being greater than or equal to the second

Logical Operators:

And Checks if two or more statements are true
&& Same as And
Or Checks if at least one of two statements is true
|| Same as Or
Xor Checks if only one of two statements is true
! Checks if a statement is not true

Increment and Decrement Operators:

++value Pre-Increment Adds 1 to the value before processing the expression which uses the value
–value Pre-Decrement Subtracts 1 from the value before processing the expression which uses the value
value++ Post-Increment Adds 1 to the value after processing the expression which uses the value
value– Post-Decrement Subtracts 1 from the value after processing the expression which uses the value