Explanation of $ str & quot ;$ $ & quot; in php, explanation of str in php

Source: Internet
Author: User

Description of "$" in $ str in php, and description of str in php

This method is called variable.
Sometimes it is convenient to use a variable name. That is to say, the variable name of a variable can be dynamically set and used. A common variable is set through declaration, for example:

<? Php
$ A = "hello ";
?>

A variable obtains the value of a common variable as the variable name of the variable. In the preceding example, after using two dollar signs ($), hello can be used as a variable of variable. For example:

<? Php
$ A = "world ";
?>

At this time, both variables are defined: $ a's content is "hello" and $ hello's content is "world ". Therefore, it can be expressed:

<? Php
Echo "$ a $ {$ }";
?>

The following statement is more accurate and the same result is output:

<? Php
Echo "$ a $ hello ";
?>

They all output: hello world.

To use variables in an array, you must solve an ambiguous problem. When writing $ a [1], the parser needs to know that $ a [1] is used as a variable, you still want $ a as a variable and retrieve the value of [1] In the variable. The syntax for solving this problem is to use $ {$ a [1]} For the first case and $ {$ a} [1] For the second case.

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.