0

好的,所以当他们读到这篇文章时可能有人会笑,但我无法让它发挥作用。我有两个数组。

数组 1 看起来像:

Array 
(

 [525133-004-TURQ/WHT-9] => Array
    (
        [classId] => 48
        [family] => Mens Shoes
        [onOrder] => 3.000
        [cost] => 45.000
        [sell] => 95.000
        [desc] => PAUL RODRIGUEZ 6, TURQ/WHT, 9
        [invStore] => 0.000
        [code] => 525133-004-TURQ/WHT-9
    )
)

数组 2 看起来像:

Array
(

[525133-004-TURQ/WHT-9] => Array
    (
        [inv] => 0.000
    )
)

需要的结果是:

Array 
(

 [525133-004-TURQ/WHT-9] => Array
    (
        [classId] => 48
        [family] => Mens Shoes
        [onOrder] => 3.000
        [cost] => 45.000
        [sell] => 95.000
        [desc] => PAUL RODRIGUEZ 6, TURQ/WHT, 9
        [invStore] => 0.000
        [code] => 525133-004-TURQ/WHT-9
        [inv] => 0.000
    )
)

我尝试了合并,但它不起作用。请帮忙!

4

2 回答 2

3

使用array_merge_recursive

$arr1 = array(
    '525133-004-TURQ/WHT-9' => array(
        'classId' => 48,
        'family' => 'Mens Shoes',
        'onOrder' => 3.000,
        'cost' => 45.000,
        'sell' => 95.000,
        'desc' => 'PAUL RODRIGUEZ 6, TURQ/WHT, 9',
        'invStore' => 0.000,
        'code' => '525133-004-TURQ/WHT-9'
    )
);

$arr2 = array(
    '525133-004-TURQ/WHT-9' => array(
        'inv' => 0.000
    )
);

$newArray = array_merge_recursive($arr1, $arr2);

在此处查看实际操作:http: //viper-7.com/jq8CgM

于 2012-08-21T18:00:58.130 回答
0
foreach ($arr1 as $key => $v1) {
    if (isset($arr2[$key])) {
        foreach ($arr2[$key] as $k => $v) {
            $arr1[$key][$k] = $v;
        }
    }
}

如果我是正确的。

于 2012-08-21T17:58:17.367 回答