为VS的foreach VS而这是更快的通过PHP数组迭代 [英] for vs foreach vs while which is faster for iterating through arrays in php

查看:130
本文介绍了为VS的foreach VS而这是更快的通过PHP数组迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪一个是最快的,通过数组在PHP迭代?或不存在的另一个这也是更快通过遍历数组?

which one is the fastest for iterating through arrays in php? or does another exist which is also faster for iterating through arrays?

推荐答案

即使有任何差异,这种差异会如此之小,它不会在所有问题。

Even if there is any kind of difference, that difference will be so small it won't matter at all.

如果你有,比如说,一个查询数据库,它会需要很长时间相比,循环遍历结果永恒的辩论VS 的foreach VS ,而将不会改变任何事情 - 至少,如果你有数据的合理金额

If you have, say, one query to the database, it'll take so long compared to the loop iterating over the results that the eternal debate of for vs foreach vs while will not change a thing -- at least if you have a reasonable amount of data.

所以,使用:


  • 不管你喜欢

  • 任何适合您的编程标准

  • 什么是最适合您的code /应用程序

将有大量的可以/应该想着那种微优化前优化其他的东西。

There will be plenty of other things you could/should optimize before thinking about that kind of micro-optimization.

结果
如果你真的想一些数字的(即使它只是为了好玩)的,你可以做一些基准测试,看看在实践中的效果。


And if you really want some numbers (even if it's just for fun), you can make some benchmark and see the results in practice.

这篇关于为VS的foreach VS而这是更快的通过PHP数组迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆