3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = [ ['rank' => '579', 'id' => '1', 'foo' => 'a'], ['rank' => '251', 'id' => '2', 'foo' => 'b'], ]; $b = [ ['size' => 'S', 'status' => 'A', 'id' => '1', 'foo' => 'c'], ['size' => 'L', 'status' => 'A', 'id' => '2', 'foo' => 'd'], ]; $result = []; foreach (array_merge($a, $b) as $row) { $result[$row['id']] = ($result[$row['id']] ?? []) + $row; } var_export(array_values($result));
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array ( 0 => array ( 'rank' => '579', 'id' => '1', 'foo' => 'a', 'size' => 'S', 'status' => 'A', ), 1 => array ( 'rank' => '251', 'id' => '2', 'foo' => 'b', 'size' => 'L', 'status' => 'A', ), )

preferences:
91.87 ms | 402 KiB | 89 Q