PHP单引号跟双引号对待变量的不同

原创
2016-06-13 12:22:21 909浏览

PHP单引号和双引号对待变量的不同

如果一个变量放在单引号中,会被当作字符串来处理,如果是放在双引号中,则会被当值一个变量来处理(此时可以用 {}扩起来,也可以不用)。

1 php2 $txt = "hello, this is from txt";3 echo 'the word is {$txt}'; //the word is {$txt}4 echo "the word is {$txt}"; //the word is hello, this is from txt

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。