$users = [
[
"userUuid" => "032b83b4-3ad8-33fd-abd3-bfafc5eb23ba",
"name" => "Илья",
],
[
"userUuid" => "59281d2d-d81e-3556-956b-f354fd5e24a9",
"name" => "Олег",
],
];
$resources = [
['user_id' => '59281d2d-d81e-3556-956b-f354fd5e24a9', 'processed' => 145, 'assigned' => 167],
['user_id' => 'e9f60f90-3096-3848-b3e6-094e81f9b022', 'processed' => 15, 'assigned' => 177],
];
foreach ($users as $k => $item) {
foreach ($resources as $l => $resource) {
if ($resource["user_id"] == $item[$l]['userUuid']) {
$users[$k][$l] = array_merge($users[$k][$l], $resource);
break;
}
}
}
<?php
$users = [
[
"userUuid" => "032b83b4-3ad8-33fd-abd3-bfafc5eb23ba",
"name" => "Илья",
],
[
"userUuid" => "59281d2d-d81e-3556-956b-f354fd5e24a9",
"name" => "Олег",
],
];
$resources = [
['user_id' => '59281d2d-d81e-3556-956b-f354fd5e24a9', 'processed' => 145, 'assigned' => 167],
['user_id' => 'e9f60f90-3096-3848-b3e6-094e81f9b022', 'processed' => 15, 'assigned' => 177],
];
$result = array_map(function($user) use ($resources) {
$second = array_filter($resources, function($resource) use ($user) {
return $resource['user_id'] === $user['userUuid'];
});
return array_merge(
$user,
count($second) ? $second[0]: []
);
}, $users);
var_dump($result);
$result = array_map(function($user) use ($resources) {
return array_merge(
$user,
...array_filter($resources, fn($resource) => $resource['user_id'] === $user['userUuid'])
);
}, $users);
var_dump($result);
$result = array_map(fn($u) => array_merge($u, ...array_filter($resources, fn($r) => $r['user_id'] === $u['userUuid'])), $users);
var_dump($result);
foreach($users as $key => $item) {
$result = array_search($item["userUuid"], array_column($resources, 'user_id'));
if($result !== false) {
$users[$key] = [$item + $resources[$result]];
}
}
var_dump($users);