【发布时间】:2011-07-13 12:17:11
【问题描述】:
可能重复:
Difference between single quote and double quote string in php
嗨,
PHP 中echo 'Test Data'; 和echo "Test Data"; 有什么区别。
两个语句都给我相同的输出。
【问题讨论】:
可能重复:
Difference between single quote and double quote string in php
嗨,
PHP 中echo 'Test Data'; 和echo "Test Data"; 有什么区别。
两个语句都给我相同的输出。
【问题讨论】:
我相信双引号允许变量被值替换:
echo "test = $test";
显示:
测试 = 2
echo 'test = $test';
显示:
测试 = $测试
【讨论】:
单引号字符串不会有解释器扩展的变量或转义序列,而双引号字符串会 - 查看不同的输出:
$foo = 'bar';
echo 'This is a $foo';
echo "This is a $foo";
因此,单引号字符串稍微“更好”地使用,因为解释器不必检查字符串的内容以获取变量引用。
【讨论】:
"This is a $foo." 而不是'This is a ' . $foo . '.'。)