PHP,单引号或双引号的速度更快? [英] What is faster in PHP, single or double quotes?

查看:144
本文介绍了PHP,单引号或双引号的速度更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
单引号与在php中使用双引号?

Possible Duplicate:
Is there a performance benefit single quote vs double quote in php?

单引号或双引号哪个更快?为什么?

Which is faster, single or double quotes and why?

此外,使用这两种方法的优点是什么?

Also, what is the advantage of using either method?

推荐答案

取决于您要执行的操作.我只是做了一些基准测试,并用5个测试用例测试了字符串分配:双引号+变量,双引号,双引号和字符串附加,单引号以及带字符串附加的单引号.

Depends what you want to do. I just did some benchmarks and tested string assignment with a 5 test cases: double quotes + variable, double quotes, double quotes and string append, single quotes, and single quotes with string append.

我的测试代码.一百万个循环.字符串分配.

My test code. A million loops. String assignment.

<?php

$start = microtime(true);

$str = "";

for($i = 0; $i<1000000; $i++)
{
        $str = "hello $i";
}

$end = microtime(true);

echo $end - $start;

结果:

不带变量的单引号和双引号字符串同样快. (每个回显.08左右). 具有变量串联的单引号和双引号字符串大致相同,但比没有变量慢. (每个都在.17-.20附近回显) 字符串中带有变量的双引号最慢(大约.20-.25)

Single and Double quotes strings without variables are equally as fast. (each echoed around .08). Single and Double quote string with variable concatenation are about the same, but slower than no variable. (each echoed around .17-.20) Double quotes with a variable in the string was slowest (around .20-.25)

单/双无关紧要,但是字符串连接似乎比变量替换要快.

So Single/Double doesn't really matter, but it seems string concatenation is faster than variable replacement.

这篇关于PHP,单引号或双引号的速度更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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