PHP Boolean self-increment and self-reduction use detailed

Source: Internet
Author: User
This time for everyone to bring PHP Boolean self-increment and self-reduction use of the detailed, PHP Boolean self-increment and self-reduction of the use of attention to what, the following is the actual case, take a look.

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) 1bool (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.

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

Php+ajax to get the news data case detailed

PHP uses Curl to clone IP and refer steps

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.