Sinsing analysis of precedence in PHP variables

Source: Internet
Author: User
Because PHP is a scripting language, so its excessive flexibility, it will lead to ambiguity in parsing, in general, we want to avoid these ambiguities, here to give a small example, friends may wish to see the following code will output what:

 
 "echo" {$var}_$var_ ";


For the above code, the first echo will always output "Worldworld", because it will not parse the $var alone, but parse into $var_, and the latter will parse into Hello_world, that is, we use curly braces to force the change of its priority.


In fact, there is a very classic example, that is, on the array, directly paste code:

There is more than one explanation in the Daijie code, and the PHP interpreter does not know what is right. $c = Array (' d ' = ' e '); echo "{$c}[' d ']"; array[' d '] $c = array (' d ' = ' e '); echo "${c[' d ']}"; E

Above, we use curly braces to change its precedence, and for specific examples there is little explanation. By the way, this article mainly refer to SF, paste the Portal: http://segmentfault.com/q/1010000000120010


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

  • 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.