常量储存在变量里为什么用单引号也行?
phpcn_u224
phpcn_u224 2016-12-24 13:19:25
0
2
971
phpcn_u224
phpcn_u224

reply all(2)
数据分析师

Why is it okay to use single quotes when constants are stored in variables? - PHP Chinese website Q&A - Why is it okay to use single quotes when constants are stored in variables? - PHP Chinese website Q&A

Take a look around and learn.

阿神

PHP单引号及双引号均可以修饰字符串类型的数据,如果修饰的字符串中含有变量(例$name);最大的区别是: 双引号会替换变量的值,而单引号会把它当做字符串输出。

例如:

<?php
         $name="string";
        echo  " 字符串" . '$name';
        echo   "字符串" .  "$name"; 
?>

结果:

         字符串$name

         字符串string

还有重要的一点点:单引号和双引号区别的意义

当所发送的数据中涉及到单引号和双引号时,在打印双引号时使用单引号,反之亦然,如:

echo 'She said,"How are you?"'; 

print "I'm just ducky.";

希望能帮到你

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template