Arrays & Loops Screencast


Representation of the Student Array

Table 1: Representation of the Student Array
Valuealicebobcharlie
Index012

Final Source Code

Here is the final source code that was developed during the screencast:

<?php
// create an array of students
$students = array("alice", "bob", "charlie");

// use a for loop to traverse the array
for($i = 0; $i < count($students); $i++) {
	echo "for loop: student $i is " . $students[$i] . "<br />";
}

// use a foreach loop to traverse the array
foreach($students as $i => $student) {
	echo "foreach loop: student $i is $student<br />";
}