array_unique然后重新编号键[重复]

时间:2022-10-25 09:25:09

Possible Duplicate:
Re-index numeric array keys

可能重复:重新索引数字数组键

I have an array as follows

我有一个数组如下

Array
(
    [0] => 15/11/2012 - 18/11/2012
    [1] => 15/11/2012 - 18/11/2012
    [2] => 15/11/2012 - 18/11/2012
    [3] => 15/11/2012 - 18/11/2012
    [4] => 19/12/2012 - 24/12/2012
    [5] => 24/12/2012 - 01/01/2013
    [6] => 24/12/2012 - 01/01/2013
    [7] => 16/01/2013 - 01/02/2013
)

I am using array_unique to remove the duplicates which is giving me

我正在使用array_unique删除给我的重复项

    Array
(
    [0] => 15/11/2012 - 18/11/2012
    [4] => 19/12/2012 - 24/12/2012
    [5] => 24/12/2012 - 01/01/2013
    [7] => 16/01/2013 - 01/02/2013
)

How can I change the keys so that they are consecutive - as below

如何更改键以使它们连续 - 如下所示

    Array
(
    [0] => 15/11/2012 - 18/11/2012
    [1] => 19/12/2012 - 24/12/2012
    [2] => 24/12/2012 - 01/01/2013
    [3] => 16/01/2013 - 01/02/2013
)

thanks in advance

提前致谢

1 个解决方案

#1


74  

Easiest way would be to put them into a new array either via a loop, or better yet array_values function.

最简单的方法是通过循环或更好的array_values函数将它们放入新数组中。

$new_array = array_values($original_array)

$ new_array = array_values($ original_array)

More information

更多信息

#1


74  

Easiest way would be to put them into a new array either via a loop, or better yet array_values function.

最简单的方法是通过循环或更好的array_values函数将它们放入新数组中。

$new_array = array_values($original_array)

$ new_array = array_values($ original_array)

More information

更多信息