douqiandai4327 2010-01-28 16:46
浏览 66

添加两个关联数组的最佳方法是什么,这样就不会重复写入重复值:`+`或`array_merge`? [重复]

This question already has an answer here:

What is the best way to add two associative arrays such that duplicate values are not over written : + or array_ merge ?

I was pretty sure that using + operator I can add two associative arrays such that duplicate values are not over written but this Answer is saying something different and so am not sure if it is really true.

I would really appreciate if you can share some lights on how can we add two associative arrays such that duplicate values are not over written.

Appreciate your time and responses.

</div>
  • 写回答

5条回答

  • dqhdpppm02183 2010-01-28 16:51
    关注

    array_merge will combine the arrays such that no values are lost, provided the arrays have contiguous numeric keys. If you start mixing string keys, values with the same keys will be overwritten. If you treat your arrays as arrays and not maps, array_merge will do what you want.

    评论

报告相同问题?

悬赏问题

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