Explanation of "$" in $ str in php, explanation of str in php _ PHP Tutorial

Source: Internet
Author: User
For details about $ str in php, refer to str in php. $ In $ str in php. in php, str is called Variable variables. sometimes it is very convenient to use variable names. That is to say, the variable name of a variable can be dynamically set to "$" in $ str in php, and 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:

<?phpecho "$a ${$a}";?> 

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

<?phpecho "$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.

The above is all the content of this article. I hope you will like it.

Description of "$" in explain $ str. in php, str is called Variable variables. sometimes it is very convenient to use variable names. That is to say, the variable name of a variable can be dynamically set...

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.