PHP run-priority face test

Source: Internet
Author: User


Take a look at the topic first

echo ' 1 '. Print (2) +3;

The correct result should be

511 for this answer, I say "! @##¥%¥% ... ", there is no way the answer is true.
So let's analyze why this is the answer, as the title says, this is a priority PHP topic for a pit dad, and that's an analysis of priority thinking (back-pushing).

1. Execute Print First

Print (2) +3;//is equivalent to print (2+3), at which point the buffer output is 5. Don't ask me why, the manual says.

2, print is a function, there are return results, int type

Print (5);//The result equals 1, this time echo ' 1 '. 1, at which point the buffer output 11

3, the final result (in order of output): 511

Add some knowledge about PHP priority:

Operator Precedence


The following table lists the precedence of operators from low to high.
Combining directional operators
Left
Left or
Left XOR
Left and
Right print
right = = = = *=/=. =%= &= |= ^= ~= <<=->>=
Left? :
Left | |
Left &&
Combining directional operators
Left |
Left ^
Left &
No = =!= = =!==
No < <= > >=
Left << >>
Left +-.
Left */%
Right! ~ + +-(int) (float) (string) (array) (object) @
Right
No new

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.