Home > Backend Development > PHP Tutorial > Teach you how to add variables to PHP strings_PHP Tutorial

Teach you how to add variables to PHP strings_PHP Tutorial

WBOY
Release: 2016-07-15 13:29:24
Original
1078 people have browsed it

We are using but need to add variable descriptions to the PHP string, although the following example has no errors:

<ol class="dp-xml">
<li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN>   </SPAN></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>temp</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>array</FONT></SPAN><SPAN>("one" =</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong></span><span> 1, "two" =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> 2);   </span>
</li>
<li class="alt"><span>// 输出:: The first element is 1   </span></li>
<li class=""><span>echo "The first element is $temp[one].";   </span></li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>   </span>
</li>
</ol>
Copy after login

But if the following echo statement is not enclosed in double quotes, an error will be reported, so it is recommended to use curly braces:

<ol class="dp-xml">
<li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN>   </SPAN></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>temp</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>array</FONT></SPAN><SPAN>("one" =</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong></span><span> 1, "two" =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> 2);   </span>
</li>
<li class="alt"><span>echo "The first element is {$temp["one"]}.";   </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>   </span>
</li>
</ol>
Copy after login

The above is the specific solution for adding variables to PHP strings.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446370.htmlTechArticleWhat we need to add to the PHP string is the variable description, although the following example has no errors: ? php $ temp = array ("one"= 1,"two"= 2); //Output: :Thefirstelementis1...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template