I have an multidimensional array which I’m trying to output as a table,
here is my array;
$marksarray=
array(3) {
[0]=>
array(2) {
[0]=>
string(1) "8"
[1]=>
string(1) "0"
}
[1]=>
array(2) {
[0]=>
string(1) "9"
[1]=>
string(1) "1"
}
[2]=>
array(2) {
[0]=>
string(2) "13"
[1]=>
string(1) "2"
}
}
So far I have my code like this;
echo "<table><tr><td>Question</td><td>Rating</td></tr>";
foreach ($marksarray as $mks){
foreach ($mks as $qid=>$rate){
echo "<tr><td>".$qid."</td><td>".$rate."</td></tr>";
}
}
echo "</table></div>";
But my output is;

What is that i’m doing wrong?
You’ve got one too many
foreach‘s going on there. Try this instead:For future reference, it makes your code far easier to understand if you use an array of associative arrays with meaningful keys. e.g.
Then your loop would look like this:
Better still, you should use MVC (Model, View, Controller) and pass this data into a view…but that’s another subject entirely.