我得到了主数组键 a1 和 a2。
$array1 = array(a1=>array(200,300,300), a2=>array(100,600,200));
$array2 = array(a1=>array('gen','gen2','gen'), a2=>array('gen2','gen3','gen3'));
我希望我的输出是
'a1'=>array(
'gen'=>200
'gen2'=>300
'gen'=>300
),
'a2'=>array(
'gen2'=>100
'gen3' =>600
'gen3' =>200
)
或者
'a1'=>array(
'gen'=>500
'gen2'=>300
)
'a2'=>array(
'gen2'=>100
'gen3'=>800
)
我已经尝试过这段代码但还不够,它不显示重复项,或者如果它显示重复键值的总和会更好
<?php
$array1 = array(a1=>array(200,300,300), a2=>array(100,600,200));
$array2 = array(a1=>array('gen','gen2','gen'), a2=>array('gen2','gen3','gen3'));
$result = array();
foreach($array1 as $k => $v) {
$result[$k] = array_combine($array2[$k], $v);
}
print_r($result);
?>
非常感谢您的帮助