我认为双引号允许变量被它们的值替换:
echo "test = $test";
显示:
test = 2
echo 'test = $test';
显示:
test = $test
单引号字符串不会被解释器扩展变量或转义序列,而双引号字符串会 - 观察以下两者不同的输出:
$foo = 'bar';
echo 'This is a $foo';
echo "This is a $foo";
"This is a $foo."
而不是'This is a ' . $foo . '.'
)。 - Gavin Ballard