Hello PHP experts,
I've used the search to try to learn by other examples, but i'm not having much luck figuring this out.
I have a multidimensional array (created out of some XML) as follows:
$data = array("RESPONSE" =>
array("ITEMS" => (
array(
"ITEM1" => array("DATE" => "20/12/2011", "RESULT1" => 2, "RESULT2" => 5, "RESULT3" => 16),
"ITEM2" => array("DATE" => "21/12/2011", "RESULT1" => 8, "RESULT2" => 9, "RESULT3" => 12),
"ITEM3" => array("DATE" => "22/12/2011", "RESULT1" => 3, "RESULT2" => 7, "RESULT3" => 19)
)
)
)
);
echo "<pre>";
print_r($data);
echo "</pre>";
It outputs as follows in human friendly (HTML) format using the print_r:
Array
(
[RESPONSE] => Array
(
[ITEMS] => Array
(
[ITEM1] => Array
(
[DATE] => 20/12/2011
[RESULT1] => 2
[RESULT2] => 5
[RESULT3] => 16
)
[ITEM2] => Array
(
[DATE] => 21/12/2011
[RESULT1] => 8
[RESULT2] => 9
[RESULT3] => 12
)
[ITEM3] => Array
(
[DATE] => 22/12/2011
[RESULT1] => 3
[RESULT2] => 7
[RESULT3] => 19
)
)
)
)
What i want to do is get it into a table as follows:
<table>
<tr><td>Date</td><td>Result 1</td><td>Result 2</td><td>Result 3</td></tr>
<tr><td>20/12/2011</td><td>2</td><td>5</td><td>16</td></tr>
<tr><td>21/12/2011</td><td>8</td><td>9</td><td>12</td></tr>
<tr><td>22/12/2011</td><td>3</td><td>7</td><td>19</td></tr>
</table>
I have been trying to figure it out, but at this point I've got double vision from all the wasted & non-functioning PHP code (and i use the word 'code' lightly... it's more of a mess than code)....
I know i need to use foreach loops to get at the data, but I'm still a novice at PHP and I need some expert advice.
I learn best from examples, so if someone can provide me with an example of how to go about this (as well as try to explain how it works) that would be much appreciated.
Again, I have been trying to figure this out on my own, and I have tried to find examples and explanations on the Internet, but I'm afraid I'm still stuck.
Thanks for understanding and helping me out.