ptg16476052
The PHP Language 655
24
$color = 'red'; // Set the color for text on the page
$color = 'blue';
$color = $old_color; # Sets the color to the old color.
// $color = 'red';
The text that precedes // is processed by PHP, so the second line assigns the $color
variable. On the third line, I’ve turned off the assignment by commenting it out. PHP also
supports multiple-line comments, which begin with / and end with /. If you want to
comment out several lines of code, you can do so like this:
/
$color = 'red';
$count = 55; // Set the number of items on a page.
// $count = $count + 1;
/
PHP ignores all the lines inside the comments. Note that you can put the // style com-
ment inside the multiline comment with no ill effects. You cannot, however, nest multi-
line comments. This is illegal:
/
$color = 'red';
$count = 55; // Set the number of items on a page.
/ $count = $count + 1; /
/
The generally accepted style for PHP code is to use // for single-
line comments rather than #.
NOTE
Variables
Variables provide a way for the programmers to assign a name to a piece of data. In PHP,
these names are preceded by a dollar sign ($). Therefore, you might store a color in a
variable called $color or a date in a variable named $last_published_at. Here’s how
you assign values to those variables:
$color = "red";
$last_published_at = time();
The first line assigns the value "red" to $color; the second returns the value returned by
the built-in PHP function time() to $last_published_at. That function returns a time-
stamp represented as the number of seconds since what’s called the “UNIX epoch,” or
the beginning of UNIX time.