我需要将从MySQL接收的值添加到数组(PHP)中。这是我所拥有的:
$players = array(); while ($homePlayerRow = mysql_fetch_array($homePlayerResult)) { $players[] = $homePlayerRow['player_id']; }
这是唯一的方法吗?
另外 ,以下方法更快/更好吗?
$players = array(); while ($homePlayerRow = mysql_fetch_array($homePlayerResult)) { array_push($players, $homePlayerRow['player_id']); }
您可以运行它,发现在某些情况下array_push速度较慢:
http://snipplr.com/view/759/speed-test-arraypush-vs- array/
运行您的代码。请享用。