搜尋
首頁php教程php手册再谈PHP单双引号问题

 

 

/*

* php 页面执行时间统计类

*

*/

class runtime

{

    var $StartTime = 0;

    var $StopTime = 0;

  

//获取微秒

function get_microtime()

    {

        list($usec, $sec) = explode(' ', microtime());

        return ((float)$usec + (float)$sec);

    }

//记录开始时间

    function start()

    {

        $this->StartTime = $this->get_microtime();

    }

//记录结束时间

    function stop()

    {

        $this->StopTime = $this->get_microtime();

    }

//计算所用时间&取整

    function spent()

    {

        return round(($this->StopTime - $this->StartTime) * 1000, 1);

    }

}

 

 

$runtime = new runtime();

 

 

//循环次数

$count = 10000;

$str = " string";

$str_single = 'This is a';

$str_double = "This is a";

$str_single_var = 'This is a'.$str;

$str_double_var = "This is a$str";

echo '

';

 

//打印$count 次 单引号

 

$runtime->start();

for($i=0;$i

echo $str_single;

}

$runtime->stop();

$sp_single = $runtime->spent();

 

 

//打印$count 次 双引号

 

$runtime->start();

for($i=0;$i

echo $str_double;

}

$runtime->stop();

$sp_double = $runtime->spent();

 

 

//打印$count 次 单引号(混合)

 

$runtime->start();

for($i=0;$i

echo $str_single_var;

}

$runtime->stop();

$sp_single_var = $runtime->spent();

 

//打印$count 次 双引号(混合)

 

$runtime->start();

for($i=0;$i

echo $str_double_var;

}

$runtime->stop();

$sp_double_var = $runtime->spent();

 

echo '

';

 

echo '循环输出'.$count.'次,单引号用时:'.$sp_single.'  双引号用时: '.$sp_double.'  单引号(混合)用时:'.$sp_single_var.' 双引号(混合)用时:'.$sp_double_var;

 

 

?>

 

经测试发现,不混合的情况下,单引号的优势并不明显,混合时单引号效率明显优于双引号。

以后用以下格式: echo '

';  即遵循w3c标准,又不会降低效率。  

 

改日用Opcodes试试

 

如果入选,请帮忙添加     出处:http://www.3oom.com/blog/16.html



陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具