dongxiong5546 2010-05-30 23:33
浏览 55
已采纳

array_merge vs array_value用于重置数组索引

I have 1 array that I want to re-index. I have found that both array_values and array_merge functions can do the job (and I don't need 2 arrays for the array_merge function to work).

Which is faster for a very large array? I would benchmark this, but I don't know how and don't have the large array yet.

Before re-index:

Array
(
    [0] => AB
    [4] => EA
    [6] => FA
    [9] => DA
    [10] => AF
)

After re-index:

Array
(
    [0] => AB
    [1] => EA
    [2] => FA
    [3] => DA
    [4] => AF
)
  • 写回答

4条回答 默认 最新

  • donglei2288 2010-05-30 23:42
    关注

    I haven't done the benchmarks either -- and if you need to be sure, you should do them.

    That said, I would suspect that if one is preferable to the other, array_values() is going to be the way to go.

    After all, what you want to do is exactly what array_values() was designed for.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化