本文介绍了array_push()与$ array [] =....哪个最快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将从MySQL接收的值添加到数组(PHP)中.这是我所拥有的:

I need to add values received from MySQL into an array (PHP). Here is what I've got:

$players = array();

while ($homePlayerRow = mysql_fetch_array($homePlayerResult)) {
    $players[] = $homePlayerRow['player_id'];
}

这是唯一的方法吗?

,以下速度更快/更好吗?

Also, is the following faster/better?

$players = array();

while ($homePlayerRow = mysql_fetch_array($homePlayerResult)) {
    array_push($players, $homePlayerRow['player_id']);
}

推荐答案

您可以运行它,并发现在某些情况下array_push会更慢:

You can run it and see that array_push is slower in some cases:

http://snipplr.com/view/759/speed-test-arraypush-vs-array/

运行您的代码.享受.

这篇关于array_push()与$ array [] =....哪个最快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 16:46