Home > Article > Backend Development > Detailed explanation of the use of PHP Boolean value auto-increment and auto-decrement
This time I will bring you a detailed explanation of the use of PHP Boolean values for self-increment and self-decrement. What are the precautions for using PHP Boolean values for self-increment and self-decrement? The following is a practical case, let’s take a look. .
He discovered that PHP’s Boolean value is incremented. No matter how many times it is incremented, the final output is 1 This is more interesting~Self-increment and self-decrement, everyone knows the difference between $a and $a a means to take the address of a, increase the value of a in the memory, and then put the value in the register
a means taking the address of a, loading the value of a into the register, and then increasing the value of a in the memory
editor to confirm the result
$a = true; var_dump(--$a); echo PHP_EOL; echo $a; $b = false; echo PHP_EOL; var_dump(++$b);The final input result of the operation is as follows
bool(true) 1 bool(false)It is found that the result is not quite right as expected before. PHP does not do any processing for the auto-increment operation of Boolean values, and after the auto-increment is 1 is because we used echo to output, resulting in bool being forced to to query the official documentation of PHP. Unexpectedly, there was an obvious line of promptsNote:
increment/decrement Operator does not affect boolean values. Decrementing a NULL value has no effect, but increasing NULL results in 1.
# I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading: Detailed explanation of PHP ajax implementation of obtaining news data case
Detailed explanation of the steps of using curl to copy ip and refer in php
The above is the detailed content of Detailed explanation of the use of PHP Boolean value auto-increment and auto-decrement. For more information, please follow other related articles on the PHP Chinese website!