Aims:
for-loops to handle multidimensional arrays
$hughs_grades = array
(
array(72, 75, 91, 60),
array(85, 0, 0, 0),
array(57, 57, 57, 57)
);
$a = array
|
||||
| 12 | 15 | 0 | 22 | |
| 38 | 14 | 38 | 19 | |
| 0 | 6 | 90 | 19 | |
$a[$i][$j] to access the element in the
$ith row, $jth column
$a[0][0] | $a[0][1] | $a[0][2] | $a[0][3] |
$a[1][0] | $a[1][1] | $a[1][2] | $a[1][3] |
$a[2][0] | $a[2][1] | $a[2][2] | $a[2][3] |
$a[2][1]?
How would you access the value in column 3 of row 0?
What do you think $x,
$y and $z will contain after the following assignment
statements:
$x = $hughs_grades[1];
$y = $x[0];
$z = $hughs_grades[1][0];
Write statements to perform the following:
$AL1101_grades
$AL1102_lab2_grade
for-loops, againfor/foreach-loops
$a as a table:
echo "<table>";
foreach ($a as $row)
{
echo "<tr>";
foreach ($row as $element)
{
echo "<td>{$element}</td>";
}
echo "</tr>";
}
echo "</table>";
$anns_grades = array
(
'AL1101' => array(100, 95, 90, 85),
'AL1102' => array(50, 51, 51, 52),
'AL1103' => array(60, 55, 60, 65)
);
Write statements to perform the following:
$AL1101_grades
$AL1102_lab2_grade
Write PHP to output the grades as a table but include the module codes as row headers