时间:2021-07-01 10:21:17 帮助过:32人阅读
<?php $a1=array(0=>"Dog",1=>"Cat",2=>"Horse",3=>"Bird"); $a2=array(0=>"Tiger",1=>"Lion"); array_splice($a1,0,2,$a2); print_r($a1); ?>
输出:
Array ( [0] => Tiger [1] => Lion [2] => Horse [3] => Bird )例子 2
与例子 1 相同,但是输出返回的数组:
<?php $a1=array(0=>"Dog",1=>"Cat",2=>"Horse",3=>"Bird"); $a2=array(0=>"Tiger",1=>"Lion"); print_r(array_splice($a1,0,2,$a2)); ?>
输出:
Array ( [0] => Dog [1] => Cat )例子 3
length 参数设置为 0:
<?php $a1=array(0=>"Dog",1=>"Cat"); $a2=array(0=>"Tiger",1=>"Lion"); array_splice($a1,1,0,$a2); print_r($a1); ?>
输出:
Array ( [0] => Dog [1] => Tiger [2] => Lion [3] => Cat )
更多php数组函数序列之array_splice() - 在数组任意位置插入元素相关文章请关注PHP中文网!