Their application should be obvious Common PHP Operators
There are so many PHP operators. A more thorough version with more detailed explanations is given here. Below we have extracted the list of the most common.
| = |
Assign |
Used for assigning values to a variable |
| += |
Add and Asign |
Adds a value to an exisisting variable and assigns the answer to the same variable |
| -= |
Subtract and Assign |
Subtracts a value from an exisiting variable and assigns the answer to the same variable |
| *= |
Multiply and Assign |
Multiples an exisiting variable's value by another value and assigns the answer to the same variable |
| /= |
Divide and Assign |
Divides an existing variable by a value and assigns the answer to the same variable |
Pause
I know the above operators (save for the first one) may be making your head spin. Rest easy. I'll explain one of them after which the others will be a breeze.
Supposing we have a variable $price which we assign the value 20:
$price = 20;
If we wanted to add a 5.00 storage charge to the price we would say that the new $price is the previous $price plus 5:
$price = $price + 5;
This can be "short-circuited" to read thus:
$price += 5;
This means the same as -=, /= and *= but with subtraction, division and multiplication respectively.
Have we cleared the air now? Hope so. Now, Play (remember the Pause?)
| || |
Or |
Tests if EITHER one of the operands evaluate to TRUE |
| && |
And |
Tests if BOTH of the operands evaluate to TRUE |
| ^ |
Exponent |
Raises to the power of eg 10^2 (10 to the power 2) |
| == |
Equality |
Tests whether the operands are equal |
| != |
Non-Equality |
Tests if the operands are NOT equal |
| < <= > >= |
less than or equal to, Greater Than and Greater than or Equal to respectively. |
Their application should be obvious |
| * |
Multiply |
Their application should be obvious |
| / |
Divide |
Their application should be obvious |
| % |
Modulus |
Returns the remainder (modulus) eg 10%3 = 1 |
If you want to have a better look at operators, click here. Otherwise, I will assume you are okey and that things are fine. Come on {Shhh}no one will know you clicked{/Shhh}. Now... Back to Variables.