

In the first example, echo ++$a increments the variable before we echo it out.

If not, just understand that the position of the increment or decrement operator tells us when the action on the variable happens. If you have ever messed with these guys before, you know what is going on here. "" //subtracting 1 from $c before we echoĮcho $d. "" //adding 1 to $b after we echoĮcho -$c. "" //adding 1 to $a before we echo (where the. Notice the placement of the increment or decrement operator around the variable. Increment and Decrement Operatorsįour possible outcomes occur from increments and decrements.
#Php operators full
Just have fun writing out the full $a = $a + $a or $b = $b * $b. If you don’t want to use them, you don’t have too. With $b, we multiple it by itself, which gives us 49. As you can see with the variable $a, we basically add it to itself, which gives us 6.
#Php operators how to
You’re smart, and you can figure out how to use the rest of them. You can use them by throwing the assignment operators in front of the =. The rest of the assignment operators are more like shortcuts. The PHP assignment operators always have an = somewhere in the statement. You have already used one of these! See, you’re a genius and you didn’t even know it. For example, the + operator adds two numbers and returns the sum of them. We will now look at this and other assignment operators in. Like other programming languages, PHP has operators that are used to perform operations or actions on variables. An operator takes one or more values, known as operands, and performs a specific operation on them. We briefly covered the basic PHP assignment operator in the An Introduction to PHP Variables chapter. Nothing special here, they are pretty much standard across most languages. Summary: in this tutorial, you will learn about PHP operators and how to use them effectively in your script. Quick note: We are going to assume from now on that the code is inside the tags. We will just deal with the first 3 for now. Relax, how complicated can standard arithmetic operators be? In PHP there are 6 groups of operators: arithmetic, assignment, increment/decrement, comparison, logical, and array operators.
