A PHP face test

Source: Internet
Author: User

< from cnmm22:http://blog.csdn.net/cnmm22/article/details/44810929>


$a = 0;

$b = 0;

If ($a =3| | $b =3) {

$a + +;

$b + +;

}

echo$a. ",". $b;

Write the result of the run.

The result is a.

The order of operations in the 1:if of knowledge points. In fact the order is, If ($a =3| | $b =3) {= If ($a = (3| | $b =3) {because | | The priority is greater than the assignment symbol.

Knowledge Point 2:| | Short circuit function, | | This is called short circuit or, (3| | $b =3) equals how much? equals 1, because (3| | $b =3) means 3 is it true? is True, | | The subsequent assignment operation $b=3 is no longer calculated, and finally, B is 0, because $b=3 is not executed at all, and (3| | $b =3) = True.

Knowledge point 3: In if ($a =3| | $b =3) {How much after a?} It says, (3| | $b =3) = True, that a is equal to true. In PHP, it's really equal to 1,a equals 1. Incidentally, in PHP is really 1, what is false? False is not 0, but empty, nothing.

So the result, a++ =1,b++=1.

That


$a = 0;

$b = 0;

If ($a =3| $b =3) {

$a + +;

$b + +;

}

echo$a. ",". $b;

What is the result of the operation?


The answer is 4, 4.

Here to pay attention to a knowledge point, or and a short circuit or. | Yes or, while | | Is the short circuit or, (3| $b =3) equal to how much? is equal to 3, because, first or will let the back $b =3 continue operation, so, B is equal to 3, in addition, or bit operation, so, (3| $b =3) = 3, so a=3.


A PHP face test

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.