PowerPoint Slide 1

 

PowerPoint Slide 2

 

PowerPoint Slide 3

 

PowerPoint Slide 4
  • As Professor Beveridge showed us how to use a for loop in class, I want to make people aware of another way. In PHP, just like there is in Java or C++, there is an advanced for loop called a foreach. This construct allows you to iterate over arrays much easier. Here is the link providing more detail on this.
PowerPoint Slide 5

 

PowerPoint Slide 6

 

PowerPoint Slide 7

 

PowerPoint Slide 8

 

PowerPoint Slide 9

 

PowerPoint Slide 10

 

PowerPoint Slide 11

 

PowerPoint Slide 12

 

PowerPoint Slide 13

This example behaved badly when demonstrated in lecture in conjunction with the source txt file being deleted. The example has now been re-coded to be more robust and overall to behave better when the file is missing.

Note that this could have been done by replacing the 'r' in fopen with 'a+'. Not only would this save us from having to code in the if !file_exists structure, but removes the need to close the file and reopen it using the 'w' mode.