如何将数组值和键移动到数组的前面?

时间:2014-11-05 10:08:24

标签: php arrays

我有一系列值:

Array ( [0] => hello [5] => Im [50] => from [1032] => Europe [1039] => where [1117] => are [1137] => you [1873] => from? ) 

取消设置这些值并将所有内容移到前面的最佳方法是什么?

是这样的:

 Array ( [0] => hello [1] => Im [2] => from [3] => Europe [4] => where [5] => are [6] => you [7] => from? ) 

4 个答案:

答案 0 :(得分:6)

使用array_values

$myarray = array_values($myarray);

答案 1 :(得分:0)

尝试使用foreach

foreach($arr as $v) {
  $newarr[] = $v;
}

答案 2 :(得分:0)

试试这个 -

$arr = array();
foreach($arr as $value) {
   $arr[] = $v;
}

答案 3 :(得分:0)

设置一个任意数组,然后使用foreach循环:

foreach ($currentArray as $curr) {
    $arbitraryArray[] = $curr;
}

然后将其设置回$ currentArray;