php - array merge return keys

Solution:

$finalArray = []    
foreach ($topArray as $array) {
  foreach ($array as $key => $value) {
      $finalArray[$key] = $value;
  }
}

Answer

Solution:

After php v5.6 you are able to do just the following $b = array_merge(...$a); In JavaScript for modern browsers it known as flatMap (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)

Complete scenario:

<?php
    
    $a = array(
        array('aaa' => 111), 
        array('bbb' => 222),
        array('bbb' => 333),
    );
    $b = array_merge(...$a);
    var_dump($b);

?>

http://sandbox.onlinephpfunctions.com/code/390ed3354e39a8db1d59abfb79dbbd59aec7f92c

Source