我在按特定场景合并数组时遇到了麻烦。搜索类似的案例在这里没有结果。要清楚地了解我的要求是什么,请看下一个示例:
第一个数组:
Array
(
[0] => stdClass
(
[call_date] => 2013-10-22 00:00:00
[first_amount] => 10
)
[1] => stdClass
(
[call_date] => 2013-10-23 00:00:00
[first_amount] => 20
)
)
第二个数组:
Array
(
[0] => stdClass
(
[call_date] => 2013-10-22 00:00:00
[second_amount] => 30
)
[1] => stdClass
(
[call_date] => 2013-10-24 00:00:00
[second_amount] => 40
)
)
我在输出中需要什么:
Array
(
[0] => stdClass
(
[call_date] => 2013-10-22 00:00:00
[first_amount] => 10
[second_amount] => 30
)
[1] => stdClass
(
[call_date] => 2013-10-23 00:00:00
[first_amount] => 20
)
[2] => stdClass
(
[call_date] => 2013-10-24 00:00:00
[second_amount] => 40
)
)
如您所见,合并按call_date 进行。合并第一个和第二个数组中日期为 2013-10-22 00:00:00 的项目,附加第二个数组中日期为 2013-10-24 00:00:00 的项目。
尝试了许多array_merge、array_udiff、array_merge_recursive、array_map的组合,但没有任何帮助:(。
将不胜感激解决这个问题!