<?php
$array1 = [
(object) ['id' => 100, 'name' => 'Muhammad'],
(object) ['id' => 102, 'name' => 'Ibrahim'],
(object) ['id' => 101, 'name' => 'Sumayyah']
];
$array2 = [
(object) ['id' => 100, 'name' => 'Muhammad'],
(object) ['id' => 103, 'name' => 'Yusuf']
];
$merged_keyed = array_column(array_merge($array1,$array2), NULL, 'id');
ksort($merged_keyed);
print_r(array_values($merged_keyed));
- Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.14
- 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
)
)
- Output for 5.6.0 - 5.6.40
- Array
(
)
preferences:
120.76 ms | 407 KiB | 5 Q