PHP 向每个二维数组追加元素

PHP 向每个二维数组追加元素

// 原数组

$data = [
    [
        'first'=>'first_yuansu',
        'second'=>'qigemingzi',  
    ],
    [
        'third'=>'disange',
        'fourth'=>'last',
    ]   
];

//追加数组

$addArr = [
    'add'=>'test'
];
array_walk($data, function (&$value, $key, $addArr) {
    $value = array_merge($value, $addArr);
}, $addArr);
print_r($data);

// 运行结果

Array
(
[0] => Array
    (
        [first] => first_yuansu
        [second] => qigemingzi
        [add] => test
    )
[1] => Array
    (
        [third] => disange
        [fourth] => last
        [add] => test
    )

)
    A+
发布日期:2024年06月15日  所属分类:php

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: