duanlieshuang5330 2012-11-28 01:08
浏览 310
已采纳

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

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
(
    [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条回答 默认 最新

  • dsf5989 2012-11-28 01:11
    关注

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

    $new_array = array_values($original_array)

    More information

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程