Php 推到阵列的特定位置

Php 推到阵列的特定位置,php,arrays,Php,Arrays,可能重复: 如何将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', '

可能重复:

如何将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');
可能是您正在寻找的:

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

array\u splice()
这应该对你有帮助:)下面有一个答案可能与被接受有关。@RichardHedges:哇!谢谢,2年多之后,当我完全忘记它时,我标出了最好的答案。