PHP如何在数组指定位置插入元素【转】

$arr=array('a','b','c','d','e','f','g');//目标数组bai
$i_arr=array('1','2');//要插入bai的数组
$n=2;//插入的位置
array_splice($arr,$n,0,$i_arr);
print_r($arr);
Array ( 
[0] => a 
[1] => b 
[2] => 1
[3] => 2 
[4] => c
[5] => d
[6] => e
[7] => f
[8] => g 
)

来源:https://zhidao.baidu.com/question/1930394207460712987.html
更多:https://www.php.net/manual/zh/function.array-splice.php

posted @ 2020-07-07 12:20  小猿笔记  阅读(3347)  评论(1编辑  收藏  举报