I realized that I can have problems with single quotes in php arrays:
我意识到我可以在php数组中使用单引号出现问题:
<?php
$lang = array(
'tagline' => 'Let's start your project',
"h1" => "About Me"
);
?>
So I changed it to double quotes:
所以我把它改为双引号:
<?php
$lang = array(
"tagline" => "Let's start your project",
"h1" => "About Me"
);
?>
Should I use "php quote escapes", instead of what I just did? (by the way how to write "php quote escapes"?)
我应该使用“php quote escapes”而不是我刚刚做的吗? (顺便说一下如何写“php quote escapes”?)
2 个解决方案
#1
8
First of all, some people will say that simple-quoted strings are faster that double-quoted strings ; you should not care about that kind of micro-optimization : it will not make any difference for your application.
首先,有些人会说简单引用的字符串比双引号字符串更快;你不应该关心那种微优化:它对你的应用程序没有任何影响。
The difference between simple-quoted and double-quoted strings is :
简单引号和双引号字符串之间的区别是:
- with double-quoted strings, there is variable interpolations
- 使用双引号字符串,有可变插值
- with double-quoted strings, you can use some special characters like
\n
,\t
, ... - 使用双引号字符串,您可以使用一些特殊字符,如\ n,\ t,...
- with single-quoted strings, you have simple-quotes to escape.
- 使用单引号字符串,您可以使用简单引号来转义。
For reference, in the PHP manual :
供参考,在PHP手册中:
- Single quoted
- 单引号
- Double quoted
- 双引号
I would that that, in the general matter, it's mostly a matter of personnal preferences...
我认为,就一般而言,这主要是个人偏好的问题......
Personnaly, in a situation such as the one you described, I would use a double-quoted string, like you did : it make the code easier to both write and read, as you don't have to escape that quote.
Personnaly,在你所描述的情况下,我会像你一样使用双引号字符串:它使代码更容易写入和读取,因为你不必逃避该引用。
#2
2
Do whatever is most readable, assuming you don't need the double-quote special features. For me, that's using whichever quotes for the string that appear the least in the string.
假设您不需要双引号特殊功能,请执行最易读的操作。对我来说,这是使用字符串中出现最少的字符串的引号。
#1
8
First of all, some people will say that simple-quoted strings are faster that double-quoted strings ; you should not care about that kind of micro-optimization : it will not make any difference for your application.
首先,有些人会说简单引用的字符串比双引号字符串更快;你不应该关心那种微优化:它对你的应用程序没有任何影响。
The difference between simple-quoted and double-quoted strings is :
简单引号和双引号字符串之间的区别是:
- with double-quoted strings, there is variable interpolations
- 使用双引号字符串,有可变插值
- with double-quoted strings, you can use some special characters like
\n
,\t
, ... - 使用双引号字符串,您可以使用一些特殊字符,如\ n,\ t,...
- with single-quoted strings, you have simple-quotes to escape.
- 使用单引号字符串,您可以使用简单引号来转义。
For reference, in the PHP manual :
供参考,在PHP手册中:
- Single quoted
- 单引号
- Double quoted
- 双引号
I would that that, in the general matter, it's mostly a matter of personnal preferences...
我认为,就一般而言,这主要是个人偏好的问题......
Personnaly, in a situation such as the one you described, I would use a double-quoted string, like you did : it make the code easier to both write and read, as you don't have to escape that quote.
Personnaly,在你所描述的情况下,我会像你一样使用双引号字符串:它使代码更容易写入和读取,因为你不必逃避该引用。
#2
2
Do whatever is most readable, assuming you don't need the double-quote special features. For me, that's using whichever quotes for the string that appear the least in the string.
假设您不需要双引号特殊功能,请执行最易读的操作。对我来说,这是使用字符串中出现最少的字符串的引号。