php数组的插入

1
2
3
4
function array_insert(&$input, $offset, $replacement){
   array_splice($input, $offset, 0, 0);
   $input[$offset] = $replacement;
  }

当然也可以有另外一种写法。

1
2
3
function array_insert(&$array,$pos,$val){
   array_splice($array,$pos,0,array($val));
}

还有另外一种,把数组切分之后,用array_merge合并起来,这种写法就很蠢了,不写了。

Share
Posted in php by waiwai at March 13th, 2010.

Leave a Reply