how to push onto a sub-array of a multidimensional array?
12:46 29 Aug 2011

I have two arrays

$brands = Array (1=>a, 2=>b);
$titles = Array (1=>d, 2=>e);

that I want to convert to one two-dimensional array

$both = Array ( [0] => Array ( [brand] => a, [title] => d ) [1] => Array ( [brand] => b, [title] = d ) );

I can do this using a pair of for loops, each of the form

$key_brand = 0;

foreach ($brands as $brand) {
    $both[$key_brand++]['brand'] = $brand;
}

but this seems clumsy, especially if I want to merge lots of arrays like this. I don't see any standard php function that does what I want. Is there a better way to do it?

php arrays