This solution is pretty cool, however if you have an array of objects this solution won't work anymore.
Say you have a list of users and each use has multiple social media accounts.
How would you create an array that has all the social media accounts from all the users? I can't find a better solution than this...
$accounts = []; foreach ($users as $user) { $accounts = array_merge($accounts, $user['socialMediaAccounts']); }
In this case, you have to do a intermediate process
$accounts = []; foreach ($users as $user) { $accounts[] = $user['socialMediaAccounts']; } $accounts = array_merge([], ...$accounts);
A fancy way:
$accounts = array_map(static function($user){ return $user['socialMediaAccounts']; }, $users); $accounts = array_merge([], ...$accounts);
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This solution is pretty cool, however if you have an array of objects this solution won't work anymore.
Say you have a list of users and each use has multiple social media accounts.
How would you create an array that has all the social media accounts from all the users? I can't find a better solution than this...
In this case, you have to do a intermediate process
A fancy way: