2

Whats the easiest way to convert array a to b

a= [['x'=>'a'], ['y'=>'b']] 


b= ['x'=>'a', 'y'=>'b']

a and b are just two examples.

Malus Jan
  • 1,860
  • 2
  • 22
  • 26

1 Answers1

0

Using array_walk_recursive for arbitrary depth:

$b = [];
array_walk_recursive($a, function ($v, $k) use (&$b) { $new[$k] = $v; });

Using @splash58 trick with the spread operator if you have only one level deep:

$b = array_merge(...$a);
bishop
  • 37,830
  • 11
  • 104
  • 139