PHP 中的 echo 单引号和双引号

发布于 2024-10-21 10:36:44 字数 460 浏览 5 评论 0原文

可能的重复:
php中单引号和双引号字符串的区别

你好,

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

两个语句都给我相同的输出。

Possible Duplicate:
Difference between single quote and double quote string in php

Hi,

What is the difference between echo 'Test Data'; and echo "Test Data"; in PHP.

Both statements give me same output.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天涯离梦残月幽梦 2024-10-28 10:36:44

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

echo "test = $test";

显示:

测试 = 2

echo 'test = $test';

显示:

测试 = $测试

I believe that double quotes allow variables to be replaced by the value :

echo "test = $test";

displays :

test = 2

echo 'test = $test';

displays :

test = $test

格子衫的從容 2024-10-28 10:36:44

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

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

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

Single-quoted strings will not have variables or escape sequences expanded by the interpreter, whereas double-quoted strings will - look at the different output of:

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

Single-quoted strings are hence marginally 'better' to use as the interpreter won't have to check the contents of the string for a variable reference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文