Map/Merge data from a flat array into the rows of a 2d array

Viewed 90

I want to add the values of array b to array a:

$a = [[1, 2],[4, 5],[7, 8]];
$b = [3, 6, 9];

Result should be:

$result = [[1, 2, 3],[4, 5, 6],[7, 8, 9]];

I am trying this (and lots of other stuff) but don't get it.

foreach ($a as $el) {
    $i = 0; 
    $el[] = $b[$i];
    $i++;
}
5 Answers
Related