- array_merge: documentation ( source)
- var_export: documentation ( source)
- array_values: documentation ( source)
<?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));