php 双引号里面的解析

WBOY
Lepaskan: 2016-07-30 13:29:50
asal
1699 orang telah melayarinya

<code><span>echo</span><span>"This works: {<span>$arr</span>['foo'][3]}"</span>;
<span>echo</span><span>"This works too: {<span>$obj</span>->values[3]->name}"</span>;
<span>echo</span><span>"This is the value of the var named <span>$name</span>: {<span>${$name}</span>}"</span>;
<span>echo</span><span>"value of the var named by the return value of getName(): {<span>${getName()}</span>}"</span>;
<span>echo</span><span>"value of the var named by the return value of \$object->getName(): {<span>${$object->getName()}</span>}"</span>;</code>
Salin selepas log masuk

解析数组

<code><span>$juices</span> = array(<span>"apple"</span>, <span>"orange"</span>, <span>"koolaid1"</span> => <span>"purple"</span>);
<span>echo</span><span>"He drank some <span>$juices</span>[0] juice."</span>.PHP_EOL;
<span>echo</span><span>"He drank some <span>$juices</span>[koolaid1] juice."</span>.PHP_EOL;
// 有效,只有通过花括号语法才能正确解析带引号的键名
<span>echo</span><span>"This works: {<span>$arr</span>['key']}"</span>;
// 有效
<span>echo</span><span>"This works: {<span>$arr</span>[4][3]}"</span>;</code>
Salin selepas log masuk

解析变量

<code><span>echo</span><span>"This is {<span>$great</span>}"</span>;
<span>echo</span><span>"This is <span>${great}</span>"</span>;
</code>
Salin selepas log masuk

输出字符串

<code><span>$a</span> = <span>'aaaa'</span>;
<span>$c</span>[<span>'c'</span>] = <span>"ccc"</span>;
<span>$b</span> = <span>"i am '<span>$a</span>' and  '<span>$c</span>[c]' \" 我是双引号!\""</span>;
<span>echo</span><span>$b</span>; //i am <span>'aaaa'</span> and <span>'ccc'</span><span>" 我是双引号!"</span></code>
Salin selepas log masuk

{}的解析

<code><span><span>class</span><span>beers</span> {</span><span>const</span> softdrink = <span>'rootbeer'</span>;
    <span>public</span><span>static</span><span>$ale</span> = <span>'ipa'</span>;
}
<span>$rootbeer</span> = <span>'A & W'</span>;
<span>$ipa</span> = <span>'Alexander Keith\'s'</span>;
<span>// 有效,输出: I'd like an A & W</span><span>echo</span><span>"I'd like an {${beers::softdrink}}\n"</span>;
<span>// 也有效,输出: I'd like an Alexander Keith's</span><span>echo</span><span>"I'd like an {${beers::$ale}}\n"</span>;</code>
Salin selepas log masuk

解析对象

<code><span>// 有效</span>
echo "This <span>square</span> is {$<span>square</span>-><span>width</span>}00 centimeters broad.";</code>
Salin selepas log masuk

版权声明:知识取之于民,用之于民!欢迎转载,转载请开头附上本文链接,不定期更新文章!

以上就介绍了php 双引号里面的解析,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan