note 55790 added to function.array-splice
| From: | csaba at alum dot mit dot edu | Date: | Sat, 13 Aug 2005 09:31:41 +0000 |
| Subject: | note 55790 added to function.array-splice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93547@lists.php.net to get a copy of this message | ||
Appending arrays
If you have an array $a2 whose values you would like to append to an array $a1 then four methods you
could use are listed below in order of increasing time. The last two methods took significantly
more time than the first two. The most surprising lesson is that using the & incurs a time hit.
foreach ($a2 as $elem) $a1[]=$elem;
foreach ($a2 as &$elem) $a1[]=$elem;
array_splice ($a1, count($a1), 0, $a2);
$a1 = array_merge($a1, $a2);
Csaba Gabor from Vienna
----
Manual Page -- http://www.php.net/manual/en/function.array-splice.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55790
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55790&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55790&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55790&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55790&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55790&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55790&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55790&report=yes
Search -- http://master.php.net/manage/user-notes.php