php - array_unique 然后重新编号键

标签 php array-unique

Possible Duplicate:
Re-index numeric array keys

我有一个数组如下

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
)

我正在使用 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
)

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

    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
)

提前致谢

最佳答案

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

$new_array = array_values($original_array)

More information

关于php - array_unique 然后重新编号键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13596128/

相关文章:

php - 使用 null 选择具有值的列

php - 运行 Composer 返回 : "Could not open input file: composer.phar"

php - 从数据库输出内容生成双换行符

php - : in_array or array_unique? 用什么比较好

php - 如何删除重复项 php array_unique 不工作

javascript - 使用 PHP 在服务器端获取 Javascript/浏览器渲染元素

PHP删除数组中的重复项

php - 删除重复项并将重复项移动到多维数组 php 的开头

PHP 登录重定向