2012-02-15 72 views
4

可能重复:
Insert into array at a specified place推到阵列的特定位置

如何1倍或更大的值推到中间(或特定位置/索引)的阵列的? 例如:

$a = array('a', 'b', 'e', 'f'); 
array_pushTo($a, 1, 'c', 'd'); // that function i'm looking for. first parameter is the array, second is the index, and third and other are the values. 
// $a now is: array('a', 'b', 'c', 'd', 'e', 'f'); 
+0

'array_splice()'http://us3.php.net/manual/en/function.array- splice.php – 2012-02-15 15:26:28

+0

这会帮助你:) http://stackoverflow.com/questions/3797239/php-array-insert-new-item-in-any-position – ExtremeCoder 2012-02-15 15:29:01

+0

还有就是低于答案可以做被接受。 – 2014-09-04 13:50:16

回答

22

array_splice可能是你在找什么:

array_splice($a, 1, 0, array('c', 'd'));