php地址引用的效率问题分享,学习php的朋友可以看看
代码如下:
echo 'begin time:'.$begin=microtime(false).'
';//begin to count time
$array=array();
for ($i=1;$i$array[$i]=$i;
}
/*
$arr=$array;//拷贝 拷贝并打印总时间0.02
foreach ($arr as $ar) {
echo $ar.'
';
}
*/
/*
$newarr=&$array;//地址引用 时间总是控制在0.01之内 地址引用的优势体现出来了
foreach ($newarr as $r) {
echo $r.'
';
}
*/
foreach ($array as $a) {//基本是0.02 很少是0.01 为什么没有地址引用的快呢?纳闷
echo $a.'
';
}
echo 'end time:'.$end=microtime(false).'
';//end to count time
echo 'total time:'.($end-$begin);
?>
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn