+ 1
HOW TO LOOP through a multi dimensional array in PHP
$score = array("John" =>array("math" =>"50","English" =>"60"), "Sarah" =>array("math" =>"10","English" =>"20"); I want to echo out something like John had 50 in math and 60 in English
1 Respuesta
+ 4
<?php
/*
HOW TO LOOP through a multi dimensional array in PHP
*/
$score = array("John" =>array("math" =>"50","English" =>"60"), "Sarah" =>array("math" =>"10","English" =>"20"));
/*
I want to echo out something like
John had 50 in math and 60 in English
*/
foreach($score as $student => $scoredata)
{
echo "$student scores ";
$i = 1;
foreach($scoredata as $major => $score)
{
echo "$score in $major";
if($i)
{
echo " and ";
$i--;
}
}
echo "<br />";
}
?>