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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退