Home > php教程 > php手册 > 教你如何在PHP字符串中加入变量

教你如何在PHP字符串中加入变量

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:06:24
Original
964 people have browsed it

我们在对但是需要对PHP字符串中加入变量说明的是,尽管下面的例子没有错误:

<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>
<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">></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

但是如果后面那个 echo 语句没有双引号引起来的话,就要报错,因此建议使用花括号:

<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>
<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">></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

以上就是PHP字符串中加入变量的具体解决方法。


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
Latest Issues
Why can't the list be rendered?
From 1970-01-01 08:00:00
0
0
0
HTML summary
From 1970-01-01 08:00:00
0
0
0
HTML summary
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template