array_splice替换数组元素应用

array_splice替换数组元素应用

 

<?php
/**
 * QQ:5871029 Email:hel8@vip.qq.com
 * @copyright Horleun (c)2010
 * @author Horleun <Horleun@foxmail.com>
 */
$qq=array(“5″,”8″,”7″,”1″,”0″,”2″,”9″);
array_splice($qq,3);    //相当于删除后面4个数字,保留前面3个.
print_r($qq);
echo”<br/>”;

$qq=array(“5″,”8″,”7″,”1″,”0″,”2″,”9″);
$newqq=array_splice($qq,1,2);  //删除的元素返回给newqq.
print_r($newqq);
echo”<br/>”;
print_r($qq);
echo”<br/>”;

array_splice($qq,1,0,”8″);   //每次只能插入一个元素,如果是多个,则用数组插入!
array_splice($qq,2,0,”7″);
print_r($qq);
echo”<br/>”;

/*插入数组方式例子*/
$qq=array(“5″,”8″,”7″,”1″,”0″,”2″,”9”);
$newqq=array_splice($qq,1,2);  //删除的元素返回给newqq.
array_splice($qq,1,0,array(“8″,”7”));
print_r($qq);

?>

结果:

留下回复