在PHP中使用单引号和双引号进行回声[重复]

问题描述 投票:6回答:2

可能重复: Difference between single quote and double quote string in php

嗨,

PHP中的echo 'Test Data';echo "Test Data";有什么区别?

这两个陈述给我相同的输出。

php echo quotes
2个回答
11
投票

我相信双引号允许变量被值替换:

echo "test = $test";

显示:

test = 2

echo 'test = $test';

显示:

test = $ test


0
投票

单引号字符串不会有由解释器扩展的变量或转义序列,而双引号字符串将 - 查看不同的输出:

$foo = 'bar';
echo 'This is a $foo';
echo "This is a $foo";

因此,单引号字符串可以稍微“更好”使用,因为解释器不必检查字符串的内容以获取变量引用。

© www.soinside.com 2019 - 2024. All rights reserved.