douyun7718 2017-02-20 14:26
浏览 95

哪个是更快的array_merge或array_splice来合并数组?

Which is faster array_merge or array_splice to merge arrays? (using array_splice to replace nothing with the 2nd array which has the effect of merging)

array_splice looks like it might use less array copying and as a result it might be faster. Is there any research on this point?

e.g.

array_splice($a1, count($a1), 0, $a2);
$a1 = array_merge($a1, $a2); 
  • 写回答

1条回答 默认 最新

  • dsfds2343 2017-02-20 14:28
    关注

    array_merge has to check whether the input array has numeric or named keys, so it knows whether to append or merge. array_splice doesn't need to do this check.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!