DEV Community

Discussion on: Never use array_merge in a loop in PHP

Collapse
klnjmm profile image
Jimmy Klein Author • Edited on

In this case, you have to do a intermediate process

$accounts = [];
foreach ($users as $user) {
    $accounts[] = $user['socialMediaAccounts'];
}

$accounts = array_merge([], ...$accounts);
Enter fullscreen mode Exit fullscreen mode