该数组没有[0]和[2]键。
Array
(
[1] => 5.2836
[3] => 2.5749
[4] => 134.19
[5] => 5.8773
[6] => 1.3504
....
如何将其更改为:
Array
(
[0] => 5.2836
[1] => 2.5749
[2] => 134.19
[3] => 5.8773
[4] => 1.3504
....
php中有这样一个任务的内置函数吗?
答案 0 :(得分:8)
答案 1 :(得分:0)
您实际上并没有排序,看起来您想要将键重新分配给值。试试这个:
<?php
$array = array( 1 => 5.2836, 3 => 2.5749, 4 => 134.19, 5 => 5.8773, 6 => 1.3504 );
$x=0;
foreach($array as $key => $val){
$new_array[$x] = $val;
$x++;
}
echo "<pre>";
print_r($new_array);
echo "</pre>";
?>