The implementation method of self-increment and self-subtraction of PHP Boolean value

Source: Internet
Author: User
This article mainly introduces the PHP boolean value of the self-increment and self-reduction of the implementation method, has a certain reference value, now share to everyone, the need for friends can refer to

After the morning and business demand battle is over, ready to open the group to see the old drivers have no car, suddenly see @e dance nine days II sent some messages

He found that the Boolean value of PHP self-increment, no matter how many times, the final output is 1

This is more interesting ~

The difference between self-increment and decrement, + + $a and $a + + is known to everyone

++a represents the address of a, increases the value of a in memory, and then places the value in the Register
a++ represents the address of a, loads the value of a into the register, and then increases the value of a in memory.

I opened an editor to confirm the results.

$a = true;var_dump (-$a); Echo Php_eol;echo $a; $b = False;echo Php_eol;var_dump (+ + $b);

Run the final input results as follows

BOOL (TRUE)
1
BOOL (FALSE)

The findings are not as good as the previous assumptions, and PHP does not do any processing for the increment of the Boolean value, since the increment is 1 because we use the echo output, which causes the bool to be strongly turned

To query the official PHP document, did not expect a line of obvious hints

Note: The increment/decrement operator does not affect Boolean values. Decreasing the null value also has no effect, but the result of incrementing null is 1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.