note 59439 added to function.array-splice
| From: | ajd at cloudiness dot com | Date: | Wed, 07 Dec 2005 02:35:21 +0000 |
| Subject: | note 59439 added to function.array-splice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99662@lists.php.net to get a copy of this message | ||
weikard's function below is useful but it will still strip keys from array elements where the
key is an integer, whether or not it is in a string:
<?php
function array_insert (&$array, $position, $insert_array) {
$first_array = array_splice ($array, 0, $position);
$array = array_merge ($first_array, $insert_array, $array);
}
$f = array("three" => "zzz", "3" => "yyy");
$a = array("4.0" => "zzzz", "four" => "yyyy");
array_insert($a,0,$f);
var_dump($a);
// array(4) { ["three"]=> string(3) "zzz" [0]=> string(3) "yyy"
["4.0"]=> string(4) "zzzz" ["four"]=> string(4) "yyyy"
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.array-splice.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59439
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59439&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59439&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59439&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59439&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59439&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59439&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59439&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59439&report=yes
Search -- http://master.php.net/manage/user-notes.php