PHP $ $str in the "$$" of the detailed

Source: Internet
Author: User

This notation is called a mutable variable.

Sometimes it is convenient to use variable variable names. That is, the variable name of a variable can be set and used dynamically. An ordinary variable is set by a declaration, for example:

    1. $a = "Hello";
    2. ?>
Copy Code

A mutable variable gets the value of an ordinary variable as the variable name of the variable variable. In the example above, hello uses two dollar sign ($) and can be used as a variable variable. For example:

    1. $ $a = "world";
    2. ?>
Copy Code

At this point, two variables are defined: $a content is "hello" and $hello content is "world". Therefore, it can be expressed as:

    1. echo "$a ${$a}";
    2. ?>
Copy Code

The following wording is more accurate and will output the same result:

    1. echo "$a $hello";
    2. ?>
Copy Code

They all output: Hello world.

To use mutable variables with arrays, you must address an ambiguous question. This is when you write the $ $a [1], the parser needs to know if you want to $a [1] as a variable, or you want $ $a as a variable and take out the value of the variable indexed to [1]. The syntax for solving this problem is to use ${$a [1] for the first case, and ${$a}[1 for the second case).

The above mentioned is the whole content of this article, I hope you can like.

PHP, str
  • 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.