强制更改数组键以连续编号

时间:2015-03-27 08:28:12

标签: php arrays sorting

我遇到了类似下面示例的问题。 我拥有的数组输出是缺少数组键#4,

Array (    [0] => Array
      (
           [milestonename] => Start Date
           [datefrom] => 03/01/2015
       )

   [1] => Array
       (
           [milestonename] => Finish Date
           [datefrom] => 03/24/2015
       )

   [2] => Array
       (
           [milestonename] => Release Date
           [datefrom] => 03/29/2015
       )

   [3] => Array
       (
           [milestonename] => release dasa
           [datefrom] => 03/16/2015
       )

   [5] => Array
       (
           [milestonename] => dasawarsa
           [datefrom] => 03/16/2015
       )

   [6] => Array
       (
           [milestonename] => lasawara
           [datefrom] => 03/18/2015
       )

   [7] => Array
       (
           [milestonename] => testing das
           [datefrom] => 03/29/2015
       ) )

我希望这个数组键是连续编号,就像数组键一样按数字排序

Array (    [0] => Array
      (
           [milestonename] => Start Date
           [datefrom] => 03/01/2015
       )

   [1] => Array
       (
           [milestonename] => Finish Date
           [datefrom] => 03/24/2015
       )

   [2] => Array
       (
           [milestonename] => Release Date
           [datefrom] => 03/29/2015
       )

   [3] => Array
       (
           [milestonename] => release dasa
           [datefrom] => 03/16/2015
       )

   [4] => Array
       (
           [milestonename] => dasawarsa
           [datefrom] => 03/16/2015
       )

   [5] => Array
       (
           [milestonename] => lasawara
           [datefrom] => 03/18/2015
       )

   [6] => Array
       (
           [milestonename] => testing das
           [datefrom] => 03/29/2015
       ) )

2 个答案:

答案 0 :(得分:3)

使用array_values

$fixed_array = array_values($array);

答案 1 :(得分:0)

您可以使用array_values功能

$arr = array_values($arr);