<?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"
]
];
var_export(
array_values(
array_reduce(
array_merge($array1, $array2),
function ($result, $row) {
$result[$row['category_id']] = ($result[$row['category_id']] ?? []) + $row;
return $result;
},
[]
)
)
);
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.20, 8.3.0 - 8.3.8
- 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:
126.33 ms | 403 KiB | 126 Q