I have an array that looks something like that
array(
[0] => array(
'id' => 1,
'title' => 'title 1',
),
[1] => array(
'id' => 10,
'title' => 'title 10',
),
[2] => array(
'id' => 11,
'title' => 'title 11',
),
[...]
);
I want to add an element to all the sub array. It's the same element i'm adding. so the new array will look like :
array(
[0] => array(
'id' => 1,
'title' => 'title 1',
'type' => 'bag',
),
[1] => array(
'id' => 10,
'title' => 'title 10',
'type' => 'bag',
),
[2] => array(
'id' => 11,
'title' => 'title 11',
'type' => 'bag',
),
[...]
);
Is there a way to do it without iterating on the the first array?
It's gonna be a big array. I'm looking for the fastest way to do it.
array_map()
– Michael Berkowski Dec 8 '11 at 19:08without iterating
do you mean you just don't want a multiline foreach loop? – Michael Berkowski Dec 8 '11 at 19:09array_walk()
iterates the array internally, there is no magic involved. ;) – Tomalak Dec 8 '11 at 19:25