如何重新索引多维数组的子数组?

时间:2017-05-19 10:25:40

标签: php arrays multidimensional-array

我有这个数组,我希望它重新格式化以生成另一个没有array_keys的数组。这是原始数组和所需数组。

原始数组

Array
(
    [0] => Array
        (
            [id] => 75
            [date] => 2017-05-18
            [time] => 11:15:00
            [dist_id] => ss0001
            [order_no] => SS17137111520
            [paid_amount] => 0
            [balance] => 0
            [status] => peding
        )

    [1] => Array
        (
            [id] => 76
            [date] => 2017-05-18
            [time] => 16:34:00
            [dist_id] => ss0001
            [order_no] => SS17137043422
            [paid_amount] => 0
            [balance] => 0
            [status] => peding
        )        
)

预期数组

Array
(
    [0] => Array
        (
            [0] => 75
            [1] => 2017-05-18
            [2] => 11:15:00
            [3] => ss0001
            [4] => SS17137111520
            [5] => 0
            [6] => 0
            [7] => peding
        )

    [1] => Array
        (
            [1] => 76
            [2] => 2017-05-18
            [3] => 16:34:00
            [4] => ss0001
            [5] => SS17137043422
            [6] => 0
            [7] => 0
            [8] => peding
        )
)

3 个答案:

答案 0 :(得分:0)

循环数组并使用array_values从数组索引中提取值0 to N

 $new_arry =array();
 foreach($data as $row)
 {

    $new_arry[] = array_values($row);

 } 

答案 1 :(得分:0)

答案 2 :(得分:0)

希望这一行有用。

Try this code snippet here

$array=array_map('array_values', $array);
print_r($array);