Friday, 27 September 2013

How to print elements and values from two related associative arrays in PHP

How to print elements and values from two related associative arrays in PHP

I have two associative arrays. $dpt_total is a list of departments, and
the total for those departments. $cl_subtotal is a multidimensional array
of department, class and subtotal.
I want to display the department and total, then the classes associated
with that department and the subtotal for the class. For example:
vdump($dpt_total);
array(2) {
'None' ¨ float 132.88
'instore bakery' ¨ float 786.24
}
Sizes: 2
vdump($cl_subtotal);
array(2) {
'None' ¨ array(1) {
'None' ¨ float 132.88
}
'instore bakery' ¨ array(10) {
'pies' ¨ float 70.94
'cakes' ¨ float 146.71
'miscellaneous' ¨ float 25.57
'cookies' ¨ float 52.38
'brownies' ¨ float 33.96
'rolls' ¨ float 143.02
'danish' ¨ float 90.42
'bagels & pretzels' ¨ float 85.68
'breads' ¨ float 55.73
'dessert case' ¨ float 81.83
}
}
Should display:
Department Class Total
-------------------------------
None 132.88
None 132.88
Instore Bakery 786.24
pies 70.94
cakes 146.71
misc 25.57
cookies 52.38
(and so on)

No comments:

Post a Comment