I want to give each value, add an element c = 3, no foreach, no system function.
$ary =
Array
(
[0] = = Array
(
[A] = 1
[B] = 2
)
[1] = = Array
(
[A] = 1
[B] = 2
)
...
)
Goal:
Array
(
[0] = = Array
(
[A] = 1
[B] = 2
[C] = 3
)
[1] = = Array
(
[A] = 1
[B] = 2
[C] = 3
)
...
)
Reply to discussion (solution)
First, a large array of foreach, and then foreach inside Array_push.
First, a large array of foreach, and then foreach inside Array_push.
Don't want to use foreach.
I try to use Array_pad, but will only fill, cannot increase ...
$ary = Array (' a ' = = 1, ' b ' = + 2), array (' A ' = 1, ' b ' = + 2), array (' a ' = = 1, ' B ' =& Gt 2) ;//method One $res = Array_map (' Array_merge ', $ary, Array_fill (0, Count ($ary), Array (' c ' = 3)));p Rint_r ($res);// Method Two function Foo2 (& $v) { $v [' c '] = 3;} $res = $ary; Array_walk ($res, ' Foo2 ');p rint_r ($res);//Method Three function Foo3 (& $v, $k, $param) { $v = Array_merge ($v, $ param);} $res = $ary; Array_walk ($res, ' Foo3 ', Array (' C ' + 3));p Rint_r ($res);/*** php5.3 can also use closures **/