Specifications
However, if the ++ is after the $a, we are using the post-increment operator. This has a differ-
ent effect. Consider the following:
$a=4;
echo $a++;
In this case, the effects are reversed. That is, first, the value of $a is returned and printed, and
second, it is incremented. The value of this whole expression is 4. This is the value that will be
printed. However, the value of $a after this statement is executed is 5.
As you can probably guess, the behavior is similar for the -- operator. However, the value of
$a is decremented instead of being incremented.
References
A new addition in PHP 4 is the reference operator, & (ampersand), which can be used in con-
junction with assignment. Normally when one variable is assigned to another, a copy is made
of the first variable and stored elsewhere in memory. For example
$a = 5;
$b = $a;
These lines of code make a second copy of the value in $a and store it in $b. If we subse-
quently change the value of $a, $b will not change:
$a = 7; // $b will still be 5
You can avoid making a copy by using the reference operator, &. For example
$a = 5;
$b = &$a;
$a = 7; // $a and $b are now both 7
Comparison Operators
The comparison operators are used to compare two values. Expressions using these operators
return either of the logical values
true or false depending on the result of the comparison.
The Equals Operator
The equals comparison operator, == (two equal signs) enables you to test if two values are
equal. For example, we might use the expression
$a == $b
to test if the values stored in $a and $b are the same. The result returned by this expression will
be true if they are equal, or false if they are not.
PHP Crash Course
C
HAPTER 1
1
PHP CRASH
COURSE
29
03 7842 CH01 3/6/01 3:39 PM Page 29