我有以下两个对象数组:
第一个数组: $array1
Array
(
[0] => stdClass Object
(
[id] => 100
[name] => Muhammad
)
[1] => stdClass Object
(
[id] => 102
[name] => Ibrahim
)
[2] => stdClass Object
(
[id] => 101
[name] => Sumayyah
)
)
第二个数组: $array2
Array
(
[0] => stdClass Object
(
[id] => 100
[name] => Muhammad
)
[1] => stdClass Object
(
[id] => 103
[name] => Yusuf
)
)
我想合并这两个对象数组(删除所有重复项)并根据 id
排序。
期望的输出:
Array
(
[0] => stdClass Object
(
[id] => 100
[name] => Muhammad
)
[1] => stdClass Object
(
[id] => 101
[name] => Sumayyah
)
[2] => stdClass Object
(
[id] => 102
[name] => Ibrahim
)
[3] => stdClass Object
(
[id] => 103
[name] => Yusuf
)
)
原文由 M. Ahmad Zafar 发布,翻译遵循 CC BY-SA 4.0 许可协议
这 3 个简单的步骤完成了工作:
注意: @Kamran 的回答帮助我找到了这个简单的解决方案