$num = sizeof($arr)
for($i=$num;$i>4;$i--)
{
$arr[$num] = $arr[$num-1];
}
$arr[4] = $a;

解决方案 »

  1.   

    错了是$arr[$i] = $arr[$i-1]; 
      

  2.   

    <?php
    $input = array("red", "green", "blue", "yellow");
    array_splice($input, 2);
    // $input is now array("red", "green")$input = array("red", "green", "blue", "yellow");
    array_splice($input, 1, -1);
    // $input is now array("red", "yellow")$input = array("red", "green", "blue", "yellow");
    array_splice($input, 1, count($input), "orange");
    // $input is now array("red", "orange")$input = array("red", "green", "blue", "yellow");
    array_splice($input, -1, 1, array("black", "maroon"));
    // $input is now array("red", "green",
    //          "blue", "black", "maroon")$input = array("red", "green", "blue", "yellow");
    array_splice($input, 3, 0, "purple");
    // $input is now array("red", "green",
    //          "blue", "purple", "yellow");
    ?> 
      

  3.   


    是要在array中指定的某个位置,插入一个变量,而变量后面的数往后移动,
    不是替换,也不是移除.如果函数不能实现,那就只能是算法了. 
      

  4.   


    //把一楼的代码复制了一下 function array_insert($arr,$value,$insert){ //数组,第几位,插入值
        
         $num=count($arr);
         for($i=$num;$i>$insert;$i--){
            $arr[$i]=$arr[$i-1];
         }
         $arr[$insert]=$value;
         return $arr;
    }
      

  5.   

    <?php
    function array_insert($array,$pos,$val)
    {
        $array2 = array_splice($array,$pos);
        $array[] = $val;
        $array = array_merge($array,$array2);
      
        return $array;
    }
    ?>
    PHP手册上的.
      

  6.   

    lz 没看到这个例子吗?
    =================
    $input = array("red", "green", "blue", "yellow");
    array_splice($input, 3, 0, "purple");
    // $input is now array("red", "green",
    //          "blue", "purple", "yellow"); 
      

  7.   


    原来我这么粗心,现在看到了, 开始看length值是0 ,没注意