I currently have the following array:
Array
(
[group] => Array
{
[5] => group1-title
[6] => group2-title
}
[treatment] => Array
(
[5] => Array
(
[16] => Array
(
[title] => title1
[description] => description1
[price] => price1
)
[17] => Array
(
[title] => title2
[description] => description2
[price] => price2
)
[6] => Array
(
[21] => Array
(
[title] => title3
[description] => description3
[price] => price3
)
}
}
}
(In reality the array data is large so it has been cropped to give an example above)
What I am attempting to do is run a foreach loop over the array to enable to me group the data in a pricing table separate by their groups (the array keys [5] and [6])
The end result I am aiming for is the following:
Group1-Title
Title 1 | Desc | Price
Title 2 | Desc | Price
Group2-Title
Title 3 | Desc | Price
I have attempted so far with a foreach loop with an inner foreach loop. That pulls the details and echos out fine – however I can’t figure out how to successfully group the data during the foreach loop.
Here’s one way to go about it. Grab the first array item and use that for the titles. Then loop through the rest of your array using the keys from the first item to display the results. Obviously my display code is quick and dirty, but this should get you started.