In the previous article, we learned about the increment operator. If you need it, please read "Do you know this operator? 》. This time we introduce to you another operator, the decrement operator. You can refer to it if you need it.
Before, we introduced the increment operator. We understand that the increment operator performs a simple task and its operand is incremented by 1. This time we learn about the exact opposite of this operator, the decrement operator.
Let’s first understand what decrement is.
As the name suggests, decrement means gradual reduction, which means that this operator can subtract a certain number from the value each time.
After understanding this meaning, let's look at the decrement operator.
First let’s look at a small example.
<?php echo "<h3>第一次</h3>"; $a = 5; echo "首先是: " . $a-- . "<br />\n"; echo "其次是: " . $a . "<br />\n"; echo "<h3>第二次</h3>"; $a = 5; echo "首先是: " . --$a . "<br />\n"; echo "其次是: " . $a . "<br />\n"; ?>
The result of this example is
Hey, the result of this example is actually the same as the previous increment operator example. They are both It's the first time, it starts with 5, and after using the "--" operator, it becomes 4; and the second time, it starts with 4, and after using the "--" operator, it's still 4, and there's no change. It seems that this operator is very similar to the increment operator.
Then let’s take a look at this decrement operator.
The decrement operator performs the simple task of decrementing its operand by 1.
This operator mainly appears in two forms. -- appears in front of the variable that works. This is the prefix mode. The second way, -- appears after the variable that works, this is the suffix mode.
That is to say, if it is used in front of a variable, the decrement operation will be performed first, and then the variable will be output; if it is used after the variable, the variable will be output first, and then the decrement operation will be performed.
That’s all for this time. If you want to know anything else, you can click here. → →php video tutorial
The above is the detailed content of Decrement operator used by php operator. For more information, please follow other related articles on the PHP Chinese website!