复制代码 代码如下:
<?php
$arr = array('apple','banana','cat','dog');
unset($arr[2]);
print_r($arr);
?>
复制代码 代码如下:
Array ( [0] => apple [1] => banana [3] => dog )
复制代码 代码如下:
<?php
function array_remove(&$arr, $offset)
{
array_splice($arr, $offset, 1);
}
$arr = array('apple','banana','cat','dog');
array_remove($arr, 2);
print_r($arr);
?>
复制代码 代码如下:
Array ( [0] => apple [1] => banana [2] => dog )
复制代码 代码如下:
<?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);
?>
//output : Array ( [0] => Tiger [1] => Lion [2] => Horse [3] => Bird )
复制代码 代码如下:
<?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));
?>
//output : Array ( [0] => Dog [1] => Cat )
复制代码 代码如下:
<?php
// length 参数设置为 0
$a1=array(0=>"Dog",1=>"Cat");
$a2=array(0=>"Tiger",1=>"Lion");
array_splice($a1,1,0,$a2);
print_r($a1);
?>
//output : Array ( [0] => Dog [1] => Tiger [2] => Lion [3] => Cat )
新闻热点
疑难解答