Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 单双引号的区别 #22

Open
senkorl opened this issue Aug 2, 2020 · 0 comments
Open

PHP 单双引号的区别 #22

senkorl opened this issue Aug 2, 2020 · 0 comments

Comments

@senkorl
Copy link

senkorl commented Aug 2, 2020

  1. 对变量的解析不同
    PHP 会解析双引号中的变量,而不会解析单引号中的变量。也就是说,如果使用单引号定义的字符串中出现变量,在输出时变量会被原样输出,不会解析成变量的值。而如果使用双引号定义的字符串中存在变量,在输出时变量会被解析为具体的值。
  2. 转义的字符不同
    单引号和双引号中都可以使用转义字符\,但是,在单引号定义的字符串中只能转义单引号和转义符本身,而在双引号定义的字符串中,PHP 可以转义更多的特殊字符。
  3. 解析速度不同
    因为单引号不需要考虑变量的解析,所以处理速度比双引号要快,我们在定义字符串时应该尽量遵循能用单引号尽量用单引号的原则。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant