Home > php教程 > php手册 > 小结:几点提高php序运行效率的方法

小结:几点提高php序运行效率的方法

WBOY
Release: 2016-06-21 09:01:06
Original
927 people have browsed it

1、用i+=1代替i=i+1。符合c/c++的习惯,效率还高。

2、尽可能的使用PHP内部函数。自己编写函数之前要详细查阅手册,看有没有相关的函数,否则费力不讨好。

3、能使用单引号字符串尽量使用单引号字符串。单引号字符串的效率要高于双引号字符串。

4、用foreach代替while遍历数组。遍历数组时foreach的效率明显高于while循环,而且不需要调用reset函数。两种遍历方法如下:

reset ($arr);
while (list($key, $value) = each ($arr)) {
echo "Key: $key; Value: $value
n";
}
foreach ($arr as $key => $value) {
echo "Key: $key; Value: $value
n";
}

以上几点均经过笔者的测试,不足之处,请多指正。



Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template