note 83388 added to function.array-push
| From: | bxi at apparoat dot nl | Date: | Fri, 23 May 2008 11:29:36 +0000 |
| Subject: | note 83388 added to function.array-push | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139638@lists.php.net to get a copy of this message | ||
I've done a small comparison between array_push() and the $array[] method and the $array[]
seems to be a lot faster.
<?php
$array = array();
for ($x = 1; $x <= 100000; $x++)
{
$array[] = $x;
}
?>
takes 0.0622200965881 seconds
and
<?php
$array = array();
for ($x = 1; $x <= 100000; $x++)
{
array_push($array, $x);
}
?>
takes 1.63195490837 seconds
so if your not making use of the return value of array_push() its better to use the $array[] way.
Hope this helps someone.
----
Server IP: 89.248.170.61
Probable Submitter: 212.203.31.1
----
Manual Page -- http://www.php.net/manual/en/function.array-push.php
Edit -- https://master.php.net/note/edit/83388
Del: integrated -- https://master.php.net/note/delete/83388/integrated
Del: useless -- https://master.php.net/note/delete/83388/useless
Del: bad code -- https://master.php.net/note/delete/83388/bad+code
Del: spam -- https://master.php.net/note/delete/83388/spam
Del: non-english -- https://master.php.net/note/delete/83388/non-english
Del: in docs -- https://master.php.net/note/delete/83388/in+docs
Del: other reasons-- https://master.php.net/note/delete/83388
Reject -- https://master.php.net/note/reject/83388
Search -- https://master.php.net/manage/user-notes.php