Parsing inside php double quotes

WBOY
Release: 2016-07-30 13:29:50
Original
1613 people have browsed it

echo"This works: {$arr['foo'][3]}"; echo"This works too: {$obj->values[3]->name}"; echo"This is the value of the var named $name: {${$name}}"; echo"value of the var named by the return value of getName(): {${getName()}}"; echo"value of the var named by the return value of \$object->getName(): {${$object->getName()}}";
Copy after login

解析数组

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

解析变量

echo"This is {$great}"; echo"This is ${great}"; 
Copy after login

输出字符串

$a = 'aaaa'; $c['c'] = "ccc"; $b = "i am '$a' and '$c[c]' \" 我是双引号!\""; echo$b; //i am 'aaaa' and 'ccc'" 我是双引号!"
Copy after login

{}的解析

classbeers {const softdrink = 'rootbeer'; publicstatic$ale = 'ipa'; } $rootbeer = 'A & W'; $ipa = 'Alexander Keith\'s'; // 有效,输出: I'd like an A & Wecho"I'd like an {${beers::softdrink}}\n"; // 也有效,输出: I'd like an Alexander Keith'secho"I'd like an {${beers::$ale}}\n";
Copy after login

解析对象

// 有效 echo "This square is {$square->width}00 centimeters broad.";
Copy after login

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

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

Related labels:
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!