We’re going to cover quite a lot of ground in this section. It’s not too difficult, but I recommend that you work your way through it carefully, as it sets the foundation for everything else in this book. As always, there are some useful questions at the end of the chapter that you can use to test how much you’ve learned.
There are two ways in which you can add comments to your PHP code. The first turns a single line into a comment by preceding it with a pair of forward slashes, like this:
// This is a comment
This version of the comment feature is a great way to temporarily remove a line of code from a program that is giving you errors. For example, you could use such a comment to hide a debugging line of code until you need it, like this:
// echo "X equals $x";
You can also use this type of comment directly after a line of code to describe its action, like this:
$x += 10; // Increment $x by 10
When you need multiple-line comments, there’s a second type of comment, which looks like Example 3-2.
Example 3-2. A multiline comment
<?php /* This is a section of multiline comments that will not be interpreted */ ?>
You can use the
*/ pairs of characters to open and close
comments almost anywhere you like inside your code. Most, if not all,
programmers use this construct to temporarily comment out entire
sections of code that do not work or that, for one reason or another,
they do not wish to be interpreted.
A common error is to use
*/ to comment ...