note 74027 added to function.array-splice
| From: | phpbarryhuntercouk at osu1 dot php dot net | Date: | Wed, 21 Mar 2007 13:01:08 +0000 |
| Subject: | note 74027 added to function.array-splice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124660@lists.php.net to get a copy of this message | ||
Following on from weikard's function here is a slight variation that accepts a key in the
associative array to insert the new array after, instead of simply an index.
<?php
function array_insert(&$array, $position, $insert_array) {
if (!is_int($position)) {
$i = 0;
foreach ($array as $key => $value) {
if ($key == $position) {
$position = $i;
break;
}
$i++;
}
}
$first_array = array_splice ($array, 0, $position);
$array = array_merge ($first_array, $insert_array, $array);
}
?>
----
Server IP: 194.145.210.3
Probable Submitter: 83.67.60.250
----
Manual Page -- http://www.php.net/manual/en/function.array-splice.php
Edit -- https://master.php.net/note/edit/74027
Del: integrated -- https://master.php.net/note/delete/74027/integrated
Del: useless -- https://master.php.net/note/delete/74027/useless
Del: bad code -- https://master.php.net/note/delete/74027/bad+code
Del: spam -- https://master.php.net/note/delete/74027/spam
Del: non-english -- https://master.php.net/note/delete/74027/non-english
Del: in docs -- https://master.php.net/note/delete/74027/in+docs
Del: other reasons-- https://master.php.net/note/delete/74027
Reject -- https://master.php.net/note/reject/74027
Search -- https://master.php.net/manage/user-notes.php