几点提高php序运行效率的方法
Release: 2016-06-21 09:06:39
Original
938 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";
}
以上几点均经过笔者的测试,不足之处,请多指正。
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31