oussama kamal
oussama kamal

Reputation: 1037

Flatten a 2d array to a 1d array

How can I convert this array:

Array
(
    [0] => Array
        (
            [Guy] => he
        )

    [1] => Array
        (
            [Girl] => she
        )

)

to this one:

Array
   (
      [Guy] => he,
      [Girl] => she
   )

I tried implode(), but it did not work.

Upvotes: 0

Views: 43

Answers (1)

jedrzej.kurylo
jedrzej.kurylo

Reputation: 40909

The code below will do the trick:

$result = [];

foreach($yourArray as $innerArray) {
  $result = array_merge($result, $innerArray);
}

Upvotes: 4

Related Questions