note 28725 modified in function.array-push by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:48:24 +0000 |
| Subject: | note 28725 modified in function.array-push by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79823@lists.php.net to get a copy of this message | ||
For the note above: you can use array_splice function to insert a new value (or array) in the middle
of array, this will work like your code does:
<?php
$list = array(
"0" => "zero",
"1" => "one",
"2" => "two",
"3" => "three",
"4" => "four",
"5" => "five",
"6" => "six"
);
$value = "New Number Three";
$key = "3";
$new = array_splice($list, $key, 0, $value);
?>
--was--
For the note above: you can use array_splice function to insert a new value (or array) in the middle
of array, this will work like your code does:
$list = array(
"0" => "zero",
"1" => "one",
"2" => "two",
"3" => "three",
"4" => "four",
"5" => "five",
"6" => "six"
);
$value = "New Number Three";
$key = "3";
$new = array_splice($list, $key, 0, $value);
http://php.net/manual/en/function.array-push.php