I want to give each value, add an element C + 3, there is no system function ah

Source: Internet
Author: User
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 **/
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.