Module Two - Textbook Assignments

The assignment details are here.


Chapter 1: Introducing Constants

Constants are not variables. However, they can temporarily store a value. In this case, the define() function is used instead of an '='. define() can pass two parameters: name and value. The first parameter, name, is usually in all capitals to differentiate it from the strings or numbers that may follow it. When calling a constant, it is important to call it by itself (or with a concatenation operator) instead of with a string. Otherwise, PHP will think it is text. The sample program that I followed uses the define() function to create a constant for 'Today'. With the constant 'Today' and other predefined constants, it can create a message. In this particular part of the chapter, I learned about the basic use of a constant. As said in the textbook, it is important to know it in order to build upon it in later chapters.

This is my working sample program from Chapter 1.


Chapter 2: For and While Loops

In this example, 'for' loops were used to create a pull-down calendar instead of 'foreach' because it takes less code to write it. From my previous knowledge of C++, I was able to understand what PHP was doing with this program. For the 'days' loop, the length had to be less than or equal to 31 in order to have all 31 days available in the menu. This concept is also true for the 'years' loop. This example gave me great insight on how websites create their drop down menu for users to interact with.

This is my working sample program from Chapter 2.


Chapter 3: Multiple Files

For this section of chapter 3, I learned how to 'include' files within one main page. Using the include() function, I was able to connect the header and footer files to the website template and give it a bit more 'oomph'. This method makes the main file more readable and less crowded with unecessary code.

This is my working sample program from Chapter 3.