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>
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>
The above is the specific solution for adding variables to PHP strings.