为什么用单引号括起来的字符串不会插入PHP中包含的变量名,而用双引号括起来会插入


Why a string surrounded with single quotes will not interpolate the variable names it contains in PHP, while with double quotes it does?

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

如果用双引号而不是单引号将字符串括起来,我们可以将变量的名称包含在文本字符串中,并将值插入其位置。

为什么在单引号的情况下不起作用?

这正是单引号和双引号之间的预期差异,当需要由解释器替换某些内容时使用双引号,单引号告诉php字符串将按原样。