数组合并的问题提

Array
(

[0] => Array
    (
        [skuid] => 121307256
        [cmmdtyType] => 1
    )

[1] => Array
    (
        [skuid] => 121347694
        [cmmdtyType] => 1
    )

)

Array
(

[0] => Array
    (
        [skuId] => 121307256
        [price] => 103.10
        [discountRate] => 
    )

[1] => Array
    (
        [skuId] => 121347694
        [price] => 2.00
        [discountRate] => 
    )

)
2个数组,想合并成这样的,除了循环还有什么好方法吗?
Array
(

[0] => Array
    (
        [skuid] => 121307256
        [cmmdtyType] => 1
        [price] => 103.10
        [discountRate] => 
    )

[1] => Array
    (
        [skuid] => 121347694
        [cmmdtyType] => 1
        [price] => 2.00
        [discountRate] => 
    )

)

湖上湖
浏览 411回答 3
3回答

幕布斯6054654

$a = [ ['skuid' => 123, 'cmmdtyType' => 1], ['skuid' => 345, 'cmmdtyType' => 2] ]; $b = [ ['skuid' => 123, 'price' => 1, 'discountRate' => 2], ['skuid' => 345, 'price' => 1, 'discountRate' => 2], ]; $c = array_replace_recursive($a, $b); dd($c);

PIPIONE

这个就只能通过循环来做了,两个数组一起遍历

冉冉说

function my_array_merge($array1, $array2) { $result = Array(); foreach($array1 as $key => &$value) { $result[$key] = array_merge($value, $array2[$key]); } return $result; }
打开App,查看更多内容
随时随地看视频慕课网APP