php数组怎么保留数字索引?<?php
$arr=array("4","5","6"); $arr2=array();
foreach($arr as $v){
$arr2[$v]=$v;
}
print_r($arr2);
echo "<hr>";
$arr3=array_merge(array("1"=>"1","2"=>"..."),$arr2);
print_r($arr3);
?>

解决方案 »

  1.   

    print_r(array("1"=>"1","2"=>"...") + $arr2);Array ( [1] => 1 [2] => ... [4] => 4 [5] => 5 [6] => 6 ) 
    array_merge() 将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面。返回作为结果的数组。 如果输入的数组中有相同的字符串键名,则该键名后面的值将覆盖前一个值。然而,如果数组包含数字键名,后面的值将不会覆盖原来的值,而是附加到后面。 如果只给了一个数组并且该数组是数字索引的,则键名会以连续方式重新索引。
      

  2.   

    Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.手册说的挺明白的,