What can you do without operators? Not much, if you're trying to do without them in a programming language, and PHP is no exception. On Monday, we barely had time to show you a long list of the operators in PHP. Today, we're going to show you what they do.
We've already worked briefly with one of the assignment operators. Their basic function is to assign a value to a variable.
$example_variable = “An example”;
$number_variable = 1;
Spark your memory? In addition to using the = operator, you can also add a value to your variable and reassign it the new value. Like this:
$initial_value = 10;
In the above example the variable $initial_value is set to 10. Then we take the value of $initial_value and add it to itself. The line $initial_value += is the same as writing $initial_value + $initial_value. Since the value is originally set at 10, the value is now 20.
It works the same with the rest of the assignment operators. If you had used the *= operator, it would have multiplied $initial_value by itself and resulted in the new value of 100.