Return to Eli-PHP Tutorials
PHP Programming Part 3: Comments and INCLUDE in PHP Programming
1. What are the three ways that you can make comments in PHP?
Three ways to make comments in PHP are:
- After two forward slashes //, which comments out a single line of code: // This is a comment
- Alternatively, a pound sign # can also comment out a single line of code: # Also a comment
- Between /*…*/, which can comment out multiple lines of code: /*Another comment */
2. What is the PHP include function? Why is it useful?
The PHP include function grabs all the information from another file and includes it in the current file. The include function is useful because you can create one section of code, and then reuse it in multiple webpages. To edit it, you simply need to edit the one PHP script, which will automatically change it in all of the files where the script is included, rather than having to edit each of those pages manually.
An example calculator.php script from the Ullman text that uses two include statements to add the header and footer to the program. Two snips of the code are provided to show both include statements on lines 38 & 84.