Question about echo string generation

Source: Internet
Author: User
If a string has a variable, the value of the variable needs to be output. {Code ...} another way: {code ...} sometimes there are two ways to dynamically use the variable name: $ this-& amp; gt; {$ property} $ argument or $ this-& amp; gt; $ property has the same effect... if a string has a variable, the value of the variable needs to be output.


  

Another method is as follows:

$a=' hello';echo "my name is {$a}";

Sometimes there are two ways to dynamically use the variable name:
$this->{$property} = $argumentOr$this->$property
The two effects are the same, but what are the differences?

Reply content:

If a string has a variable, the value of the variable needs to be output.


   

Another method is as follows:

$a=' hello';echo "my name is {$a}";

Sometimes there are two ways to dynamically use the variable name:
$this->{$property} = $argumentOr$this->$property
The two effects are the same, but what are the differences?

There is no big difference. Using curly brackets is just to help PHP identify variables during parsing. For example, you can try:

$a = "hello";echo "$aworld";echo "{$a}world";

That is to define the variable. When a variable name is the first part of another variable name, add {} to get what you want.

$a='hello ';$aword=' word';echo "my name  is $aword";  //my name  is wordecho "
";echo "my name is {$a}word"; //my name is hello word

When echo is used, braces {} can only be used in double quotation marks.

Similar to bash, variables and strings are distinguished.

// Just to differentiate variables, as follows: $ a = "he"; // If so, your variable $ allo does not exist echo "$ allo"; // Therefore, you need to add a separator to distinguish echo "{$ a} llo"; // echo hello // This is only useful after double quotation marks. If the variables you want to print are not preceded by English or are easy to confuse with variables, you do not need to use them.

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.