0

I have an array with nested associative array for each element, like this:

array (size=47)
  0 => 
    array (size=1)
      'name' =>  'Saitama'
  1 => 
    array (size=1)
      'email' =>  'Saitama@onepunch.man'
  ...

I want to build a function that return an associative array like this:

array (size=47)
    'name' =>  'Saitama',
    'email' =>  'Saitama@onepunch.man'
  ...

I tried with array_map() and array_combine() but I cannot manage to do this job.

Thank you very much

Pasquale

ufollettu
  • 822
  • 3
  • 19
  • 45

1 Answers1

1

It's called flattening and just merge the nested arrays:

$result = call_user_func_array('array_merge', $array);

Obviously this only works with unique keys, as duplicates will be overwritten.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87