I understand that I should not provide an answer to this “non-question”. I still do so, as I think it might carry some learning value.
The idea is, not to cycle each game for each user (as the naive approach would be), as this simply doesn’t scale. It is much better to use a matching array and then sort the games into it:
//Prepare matching array
$user_games=array();
foreach ($user as $u) {
$u['game']=array();
$user_games[$u['id']]=$u;
}
//Sort games into matching array
foreach ($game as $g) {
$user_games[$g['user_id']]['game'][]=$g;
}
This way a new game will not create n cycles (n being the number of users), but only one.
print_r($user_games);
creates the desired output. If the user IDs as indices are a problem, just use
print_r(array_values($user_games);
solved how can two array marge each inside object key are matching it Cross?