例:
$a = array(
array(
'province'=>'ss',
'package' => array(
array(
'FX58'=>0,
'PName' => 'a'
),
),
'storeName'=> 'test',
),
array(
'province'=>'cc',
'package' => array (
配列(
'FX58'=>1,
'PName' => 'b'
),
),
'storeName'=> 'test2',
)
);
$b = array(
array(
'province'=>'ss',
'package' => array(
'FX58'=>1,
'PName' => 'a '
),
),
'storeName'=> 'test',
),
array(
'province'=>'cc',
'package' => array(
array(
'FX58 '=>2,
'PName' => 'b' ),
),
'storeName'=> 'test2',
)
);
将b数组值统计をa数组中へ
回复讨论(解决方案)
これは?
$new=array_merge($a,$b);echo "<pre class="brush:php;toolbar:false">";print_r($new);echo "";
分组键は哪个ですか?
将同州,storeName,,pName中FX158データ统计起来
$new=array_merge($a,$b);echo "<pre class="brush:php;toolbar:false">";print_r($new);echo "";
$a = array( array( 'province'=>'ss', 'package' => array( array( 'FX58'=>0, 'PName' => 'a' ), ), 'storeName'=> 'test', ), array( 'province'=>'cc', 'package' => array( array( 'FX58'=>1, 'PName' => 'b' ), ), 'storeName'=> 'test2', ));$b = array( array( 'province'=>'ss', 'package' => array( array( 'FX58'=>1, 'PName' => 'a' ), ), 'storeName'=> 'test', ), array( 'province'=>'cc', 'package' => array( array( 'FX58'=>2, 'PName' => 'b' ), ), 'storeName'=> 'test2', ));foreach($a as $v) { foreach($v['package'] as $t) { $res[$v['province']][$v['storeName']][$t['PName']] = $t['FX58']; }}foreach($b as &$v) { foreach($v['package'] as $t) { $res[$v['province']][$v['storeName']][$t['PName']] += $t['FX58']; }}foreach($a as &$v) { foreach($v['package'] as &$t) { $t['FX58'] = $res[$v['province']][$v['storeName']][$t['PName']]; }}print_r($a);
Array( [0] => Array ( [province] => ss [package] => Array ( [0] => Array ( [FX58] => 1 [PName] => a ) ) [storeName] => test ) [1] => Array ( [province] => cc [package] => Array ( [0] => Array ( [FX58] => 3 [PName] => b ) ) [storeName] => test2 ))
リーリー