Home >Backend Development >PHP Tutorial >提高PHP程序运行效率的四个小方法_PHP

提高PHP程序运行效率的四个小方法_PHP

WBOY
WBOYOriginal
2016-06-01 12:29:571011browse

  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:
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