【问题标题】:Make array keys to start from 0 again in php [duplicate]在php中使数组键再次从0开始[重复]
【发布时间】:2014-09-08 17:35:45
【问题描述】:

我有一个名为$Compare的数组,我在php中使用了print_r()函数:

Array ([2] => Broccoli, raw [3] => Candies, butterscotch [4] => Celery, raw [10] => Apricots, raw)

我希望键的顺序正确:0,1,2,3 而不是 2,3,4,10!

最后应该是这样的:

Array ([0] => Broccoli, raw [1] => Candies, butterscotch [2] => Celery, raw [3] => Apricots, raw)

【问题讨论】:

    标签: php arrays


    【解决方案1】:

    使用array_values:

    $Compare = array_values($Compare);
    

    【讨论】:

    • 感谢这对我有很大帮助
    猜你喜欢
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    • 2013-05-29
    • 1970-01-01
    • 2015-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多