我有多个阵列说现在2,第一阵列有城市(孟买,浦那。班加罗尔,海德拉巴) 第二阵列有Mumbia nad Hyderabd。
我想根据Key总结这些值。
阵 ( [孟买] =>排列 ( [ga:pageviews] => 1 [ga:visits] => 1 [ga:newVisits] => 1 [ga:pageviewsPerVisit] => 1 [ga:entranceBounceRate] => 1 [ga:avgTimeOnSite] => 1 [ga:timeOnSite] => 1 [ga:bounces] => 1 )
[Pune] => Array
(
[ga:pageviews] => 2
[ga:visits] => 2
[ga:newVisits] => 2
[ga:pageviewsPerVisit] => 2
[ga:entranceBounceRate] => 2
[ga:avgTimeOnSite] => 2
[ga:timeOnSite] => 2
[ga:bounces] => 2
)
[Bangalore] => Array
(
[ga:pageviews] => 3
[ga:visits] => 3
[ga:newVisits] => 3
[ga:pageviewsPerVisit] => 3
[ga:entranceBounceRate] => 3
[ga:avgTimeOnSite] => 3
[ga:timeOnSite] => 3
[ga:bounces] => 3
)
[Hyderabad] => Array
(
[ga:pageviews] => 4
[ga:visits] => 4
[ga:newVisits] => 4
[ga:pageviewsPerVisit] => 4
[ga:entranceBounceRate] => 4
[ga:avgTimeOnSite] => 4
[ga:timeOnSite] => 4
[ga:bounces] => 4
)
)
第二阵列:
阵 ( [孟买] =>排列 ( [ga:pageviews] =>五 [ga:visits] =>五 [ga:newVisits] =>五 [ga:pageviewsPerVisit] =>五 [ga:entranceBounceRate] =>五 [ga:avgTimeOnSite] =>五 [ga:timeOnSite] =>五 [ga:bounces] =>五 )
[Hyderabad] => Array
(
[ga:pageviews] => 2
[ga:visits] => 2
[ga:newVisits] => 2
[ga:pageviewsPerVisit] => 2
[ga:entranceBounceRate] => 2
[ga:avgTimeOnSite] => 2
[ga:timeOnSite] => 2
[ga:bounces] => 2
)
)
我希望结果为:
阵 ( [孟买] =>排列 ( [ga:pageviews] => 6 [ga:visits] => 6 [ga:newVisits] => 6 [ga:pageviewsPerVisit] => 6 [ga:entranceBounceRate] => 6 [ga:avgTimeOnSite] => 6 [ga:timeOnSite] => 6 [ga:bounces] => 6 )
[Pune] => Array
(
[ga:pageviews] => 2
[ga:visits] => 2
[ga:newVisits] => 2
[ga:pageviewsPerVisit] => 2
[ga:entranceBounceRate] => 2
[ga:avgTimeOnSite] => 2
[ga:timeOnSite] => 2
[ga:bounces] => 2
)
[Bangalore] => Array
(
[ga:pageviews] => 3
[ga:visits] => 3
[ga:newVisits] => 3
[ga:pageviewsPerVisit] => 3
[ga:entranceBounceRate] => 3
[ga:avgTimeOnSite] => 3
[ga:timeOnSite] => 3
[ga:bounces] => 3
)
[Hyderabad] => Array
(
[ga:pageviews] => 6
[ga:visits] => 6
[ga:newVisits] => 6
[ga:pageviewsPerVisit] => 6
[ga:entranceBounceRate] => 6
[ga:avgTimeOnSite] => 6
[ga:timeOnSite] => 6
[ga:bounces] => 6
)
)
感谢您的帮助...... 露丝。
答案 0 :(得分:0)
foreach($arr2["Hyderabad"] as $key => $val)
{
$arr1["Hyderabad"][$key] += $val;
}
那应该为你做:)
答案 1 :(得分:0)
试试这个
$newarray = $array1;
foreach ($array2 as $key => $values) {
foreach ($values as $name => $value) {
if (!is_array($newarray[$key])) { $newarray[$key] = array(); }
$newarray[$key][$name] += $value;
}
}
// $newarray should now be the array you want with values added
答案 2 :(得分:0)
让我们在名为parent
的数组中说出所有这些$parent has keys as 0,1
foreach($parent as $k=>$v)
{
foreach($v as $ik=>$iv)
{
foreach($iv as $fk=>$fv)
{
$cities[$ik][$fk] = $cities[$ik[$fk]+$fv;
}
}
}