array_column和foreach,性能明智哪个更好? [英] array_column and foreach, performance wise which is better?
本文介绍了array_column和foreach,性能明智哪个更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
与常规的foreach循环相比,我对php函数array_column的性能感到好奇。
在我的情况下,我想从数据库表中获取单列数据到数组中。我的查询结果大约有1万到5万条记录,所以我应该在这里使用常规的foreach循环还是array_column更好?
I am curious about performance of php function array_column as compared to regular foreach loop. In my case I want to get single column data from db table into array. My query results ~10k to ~50k records, so should I go with regular foreach loop or array_column is better here?
推荐答案
array_column
是一个内置函数,可能最快。因此,我的测试还显示 array_column
比foreach循环快%50。
Since array_column
is a built-in function, it would probably be fastest one. Hence my tests also showed array_column
is %50 faster than a foreach loop.
这篇关于array_column和foreach,性能明智哪个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文