-數(shù)值數(shù)組疊加的遞歸方法:幾個相同格式的數(shù)組的對應(yīng)項(xiàng)疊加,得到一個此種格式的數(shù)組
-@param array(數(shù)組1, 數(shù)組2, ...)
-@return array 數(shù)組為上面數(shù)組1,數(shù)組2,...的對應(yīng)項(xiàng)疊加
function ToOne($arr1, $arr2) {
foreach ($arr1 as $k1 => $v1) {
if (!is_array($v1)) {
$arr1[$k1] = $arr1[$k1] + $arr2[$k1];
} else {
$arr1[$k1] = ToOne($arr1[$k1], $arr2[$k1]);
}
}
return $arr1;
}
$arr1 = [
1,
'zsh' => [
2,
'zsk' => [
3,
'dihezsh' => [
4,
'dihezsk' => 5
]
]
]
];
$arr2 = [
1,
'zsh' => [
2,
'zsk' => [
3,
'dihezsh' => [
4,
'dihezsk' => 5
]
]
]
];
echo '<pre>';
print_r($arr1);
echo "</pre>";
echo '<pre>';
print_r(ToOne($arr1, $arr2));