Home >Backend Development >PHP Tutorial >In those years, the PHP self-increment and self-subtraction operations we have pursued (2)_PHP Tutorial
-------------------------------------------------- ---------------------------------------------
Let’s start with an example to highlight the key points.
$a = true;
echo $a++;
echo $a + 1;
$b = 'c';
echo $b++;
echo $b++;
------------------------@chenwei
Do you know the correct answers to the above four outputs? Here are some summarized rules. You can also experiment by yourself.
1. The Boolean type does not participate in the ++ operation, does not perform type conversion and participates in auto-increment. So the first output is 1.
2. Boolean types involved in arithmetic operations such as +, - will automatically perform type conversion, so the second output is 2.
3. The string ++ in PHP represents ascending order, so the third output is c and the fourth output is d.
-------------------------------------------------- ------------------------------------------