我应该使用单引号PHP引号逃逸或阵列使用双引号? [英] Should I use php quote escapes for single quotes or use double quotes in arrays?

查看:481
本文介绍了我应该使用单引号PHP引号逃逸或阵列使用双引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到,我可以在PHP数组单引号的问题:

I realized that I can have problems with single quotes in php arrays:

<?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"
);
?>

我应该使用PHP报价越狱,而不是什么,我只是做了?
(顺便说一下如何写PHP报价逃逸?)

Should I use "php quote escapes", instead of what I just did? (by the way how to write "php quote escapes"?)

推荐答案

首先,有些人会说简单引用的字符串会更快的双引号字符串;你不应该在乎那种微优化:它不会让你的应用程序的任何区别

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 :


  • 用双引号字符串,有可变插值

  • 用双引号字符串,就可以使用一些特殊的字符,如 \\ n \\ t ..

  • 用单引号字符串,你有简单的报价逃脱。

有关参考,在PHP手册:

For reference, in the PHP manual :

  • Single quoted
  • Double quoted

结果
我会说,在一般的问题,它是主要的personnal preferences的问题...


I would that that, in the general matter, it's mostly a matter of personnal preferences...

Personnaly,在一个情况下,如你所描述的,我会用一个双引号字符串,像你这样的:它使code更容易写和读,因为你没有逃跑该报价。

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.

这篇关于我应该使用单引号PHP引号逃逸或阵列使用双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆