Click here to view code image
<?php
define("NUM_SQUIRRELS", 10);
define("PLAYER_NAME", "Jim");
define("NUM_SQUIRRELS_2", NUM_SQUIRRELS);
echo NUM_SQUIRRELS_2;
?>
This script demonstrates how you can set constants to numbers, strings, or
even the values of other constants (although this last option doesn’t really get
used much).
References
You can use the equal sign (=) to copy the value from one variable to another
so that each one has a copy of the value. Another option here is to use
references, which is where a variable does not have a value of its own but
instead points to another variable. This enables you to share values and have
variables mutually update themselves.
To copy by reference, use the & symbol, as follows:
Click here to view code image
<?php
$a = 10;
$b = &$a;
echo $a . "\n";
echo $b . "\n";
$a = 20;
echo $a . "\n";
echo $b . "\n";
$b = 30;
echo $a . "\n";
echo $b . "\n";
?>
If you run this script, you will see that updating $a also updates $b and also
that updating $b updates $a.
Comments
Adding short comments to your code is recommended and usually a
requirement in larger software houses. In PHP, you have three options for
commenting style: //, / /, and #. The first option (two slashes) instructs