PHP: Multidimensional Arrays I

Derek Bridge

Department of Computer Science,
University College Cork

PHP: Multidimensional Arrays I

Aims:

Multidimensional arrays

2-dimensional arrays: example I

2-dimensional arrays: example II

Class exercise: accessing the elements

What do you think $x, $y and $z will contain after the following assignment statements:

  1. $x = $hughs_grades[1];
  2. $y = $x[0];
  3. $z = $hughs_grades[1][0];

Class exercise: accessing the elements

Write statements to perform the following:

  1. assign Hugh's AL1101 grades into $AL1101_grades
  2. assign his grade for the second piece of AL1102 coursework into $AL1102_lab2_grade
  3. echo his grade for the last piece of AL1103 coursework

Nested for-loops, again

Class exercise

  1. Write PHP to output Hugh's grades as a table
  2. Modify your PHP so that it also computes and echoes the average grade for each module

2-dimensional arrays: example III

Class exercise: accessing the elements

Write statements to perform the following:

  1. assign Ann's AL1101 grades into $AL1101_grades
  2. assign her grade for the second piece of AL1102 coursework into $AL1102_lab2_grade
  3. echo her grade for the last piece of AL1103 coursework

Class exercise

Write PHP to output the grades as a table but include the module codes as row headers