我有一个数组,这是一个片段:
[6 - CAMERAS & SUPPLIES] => Array
(
[CAMERAS] => Array
(
[CAMCORDERS] => Array
(
[ACTION CAMCORDERS] => Array
(
[total_ty_yest_sales] => 70.83
[total_wo_dotcom_ty_yest_sales] => 401.59
[east_ty_yest_sales] => 53.01
)
[STANDARD CAMCORDERS] => Array
(
[total_ty_yest_sales] => 96.09
[total_wo_dotcom_ty_yest_sales] => 96.09
[east_ty_yest_sales] => 68.21
)
[SURVELIANCE] => Array
(
[total_ty_yest_sales] => 84.00
[total_wo_dotcom_ty_yest_sales] => 84.00
[east_ty_yest_sales] => 26.00
)
)
[subCAMERAS] => Array
(
[BIG ZOOM] => Array
(
[total_ty_yest_sales] => 31.66
[total_wo_dotcom_ty_yest_sales] => 13.68
[east_ty_yest_sales] => 1.47
)
[PEGGED CAMERAS] => Array
(
[total_ty_yest_sales] => 13.50
[total_wo_dotcom_ty_yest_sales] => 5.50
[east_ty_yest_sales] => 5.00
)
[POINT-N-SHOOT] => Array
(
[total_ty_yest_sales] => 46.61
[total_wo_dotcom_ty_yest_sales] => 10.35
[east_ty_yest_sales] => 4.06
)
[RUGGED CAMERAS] => Array
(
[total_ty_yest_sales] => 87.04
[total_wo_dotcom_ty_yest_sales] => 87.04
[east_ty_yest_sales] => 65.20
)
[SLR] => Array
(
[total_ty_yest_sales] => 50.19
[total_wo_dotcom_ty_yest_sales] => 9.40
[east_ty_yest_sales] => 1.37
)
)
)
我在表格中显示数组:
6 - CAMERAS & SUPPLIES --sum-- --sum-- --sum--
CAMERAS --sum-- --sum-- --sum--
CAMCORDERS --sum-- --sum-- --sum--
ACTION CAMCORDERS 70.83 401.59 53.01
STANDARD CAMCORDERS 96.09 96.09 68.21
SURVEILLANCE 84.00 84.00 26.00
subCAMERAS --sum-- --sum-- --sum--
BIG ZOOM 31.66 13.68 1.47
PEGGED CAMERAS 13.50 5.50 5.00
POINT-N-SHOOT 46.61 10.35 4.06
RUGGED CAMERAS 87.04 87.04 65.20
SLR 50.19 9.40 1.37
我想总结数组每个部分的父项。即我想用孩子的总和取代“--sum--”。所以... subCameras =大变焦+挂钉相机+点对点+坚固相机+单反相机。相机=摄像机+子相机。等
这就是我对桌子的看法:
foreach($group as $gmm => $acctg_dept_nbrs) {
echo "\t\t\t\t<tr>\n\t\t\t\t\t<td>" . $gmm . "</td>\n";
foreach ($acctg_dept_nbrs as $acctg_dept_nbr => $dept_catg_grp_descs) {
echo "\t\t\t\t<tr>\n\t\t\t\t\t<td style=\"padding-left: 1em;\">" . $acctg_dept_nbr . "</td>\n";
$total_acctg_dept_nbr = 0;
foreach($dept_catg_grp_descs as $dept_catg_grp_desc => $dept_category_descs) {
echo "\t\t\t\t<tr>\n\t\t\t\t\t<td style=\"padding-left: 2em;\">" . $dept_catg_grp_desc . "</td>\n";
$total_dept_catg_grp_desc = 0;
foreach($dept_category_descs as $dept_category_desc => $dept_subcatg_descs) {
echo "\t\t\t\t<tr>\n\t\t\t\t\t<td style=\"padding-left: 3em;\">" . $dept_category_desc . "</td>\n";
$total_dept_category_desc = 0;
//$sum = array_sum($dept_subcatg_descs[])
foreach($dept_subcatg_descs as $dept_subcatg_desc => $values) {
echo "\t\t\t\t<tr>\n\t\t\t\t\t<td style=\"padding-left: 4em;\">" . $dept_subcatg_desc . "</td>\n";
//$total_dept_subcatg_desc = 0;
$sum = $values['total_ty_yest_sales'];
echo "<td>".$sum."</td>";
$sum = $values['total_wo_dotcom_ty_yest_sales'];
echo "<td>".$sum."</td>";
$sum = $values['east_ty_yest_sales'];
echo "<td>".$sum."</td>";
//$total_dept_category_desc += $sum;
}
}
}
}
}