Guide to PHP and MySQL (Computer Science 4 All Version)
Chapter 6: Working With Functions
PHP Functions
PHP functions provide a way to create a group of statements that perform a certain task and then "call" that function from PHP code.
The PHP include
Statement
PHP allows you to have a function in a separate file, such as functions.php
and, using the PHP include
or include_once
statement access that function in any PHP program.
The rendered web page would look like this:
Function Parameters
PHP allows you to pass arguments to a function by declaring them as the parameters of the function.
Using Default Function Parameters
PHP also allows you to have default values parameters if that parameter is not in the arguments passed to a function by assigning a default value to them as the parameters of the function.
Using Optional Function Parameters
PHP also allows you to have optional parameters if that parameter is not in the arguments passed to a function.
Task - Create a PHP Loop/Array/Function Page
For this task you will copy your index.php
file to a new file called lfa.php
. You will also create a file called that will hold your PHP functions. You will need to include
your functions.php
in the code for your index.php
file.
- Change your JavaScript array function to use a PHP function to display the list (with links) of assignments for this course. The function should manipulate a PHP array.
- Use appropriate PHP comments throughout your code.
- Use PHP to replace your paragraph about yourself with:
- A function that generates an HTML5/CSS table of three (3) columns: the month number, name of the month, and number of days in that month.
- This function should use PHP Arrays to the store name of the months and days in each month.
- This function should use a PHP Loop to walk through the months names array and generate HTML5/CSS to display the table.
- This function should use a PHP conditional (
if
) test to determine whether the row is odd or even and use appropriate CSS to make the even rows a different background/foreground color than the odd rows. Hint: use the PHP mod (%
) operator in yourif
statement.
- A function that generates an HTML5/CSS table of three (3) columns: the month number, name of the month, and number of days in that month.
- Modify your JavaScript code in your
index.html
file that uses an array of the Assignments for this course to display an ordered list of these assignments to convert the entry for this assignment to a web link that allows me to download and save yourindex.php
,lfa.php
,vars.php
, andfunctions.php
files so I can download, save, and grade your work.
You will modify the PHP array function for this item in your index.php
page to add a link for this assignment that allows me to view your work.
You *MUST* use the W3C Unicorn Validator to validate your HTML5/CSS3 code.
Then upload your files (images, CSS, js, php, etc.) to your bscacad3
Web Space and add <a>
(anchor) tags that utilize the 'download.php
' for all the files for this assignment that allow me to download your files to my web server.