<?php
$array1 = [
[
"total_process_per_category" => "6",
"category_id" => "1"
],
[
"total_process_per_category" => "2",
"category_id" => "2"
]
];
$array2 = [
[
"total_pinned_per_category" => "16",
"category_id" => "1"
],
[
"total_pinned_per_category" => "4",
"category_id" => "2"
]
];
$result = [];
foreach (array_merge($array1, $array2) as $row) {
$result[$row['category_id']] = ($result[$row['category_id']] ?? []) + $row;
}
var_export(array_values($result));
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- array (
0 =>
array (
'total_process_per_category' => '6',
'category_id' => '1',
'total_pinned_per_category' => '16',
),
1 =>
array (
'total_process_per_category' => '2',
'category_id' => '2',
'total_pinned_per_category' => '4',
),
)
preferences:
99.68 ms | 407 KiB | 5 Q