如果 echo 的字符串参数里含有变量,有两种情况:第一种是字符串参数用双引号,echo 输出变量的值;第二种是字符串参数使用单引号,则输出变量名。
字符串采用双引号的示例如下:
$a = "just in case";
echo "take the gun,$a";
返回的结果是:
take the gun,just in case
上例中,字符串采用双引号,在字符串里的变量输出变量的值。
再看字符串用单引号的情况。示例如下:
$a = "just in case";
echo 'take the gun,$a';
在字符串使用单引号的情况下,返回的结果是输出变量名称,而不是变量的值:
take the gun,$a