码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-07-07 13:07:11      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:定位   spl   print   插入   fun   splice   array   ida   tps   

$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

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

标签:定位   spl   print   插入   fun   splice   array   ida   tps   

原文地址:https://www.cnblogs.com/KillBugMe/p/13260057.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!