title: How to avoid array_merge in loops when dealing with array of objects
body: <p>There are a bunch of discussions around <code>'array_merge(...)' is used in a loop and is a resources greedy construction.</code></p>
  <p>For simple arrays there is an easy solution using the spread operator. E.g.</p>
  <pre class="lang-php prettyprint-override"><code>$arraysToMerge = [ [1, 2], [2, 3], [5,8] ];
  $arraysMerged = array_merge([], ...$arraysToMerge);
  </code></pre>
  <p>However, my problem is that I couldn't find a way to avoid it in the following scenario:</p>
  <p>Say you have a list of users and each use has multiple social media accounts.</p>
  <p>How would you create an array that has all the social media accounts from all the users?
  The only solution I found is something like this:</p>
  <pre class="lang-php prettyprint-override"><code>$allSocialMediaAccounts= [];
  foreach ($users as $user) {
      $allSocialMediaAccounts= array_merge($accounts, $user['socialMediaAccounts']);
  }
  </code></pre>