Specifications

String Operators
Weve already seen and used the only string operator. You can use the string concatenation
operator to add two strings and to generate and store a result much as you would use the addi-
tion operator to add two numbers.
$a = “Bob’s “;
$b = “Auto Parts”;
$result = $a.$b;
The $result variable will now contain the string “Bob’s Auto Parts”.
Assignment Operators
Weve already seen =, the basic assignment operator. Always refer to this as the assignment
operator, and read it as is set to.For example
$totalqty = 0;
This should be read as $totalqty is set to zero. Well talk about why when we discuss the
comparison operators later in this chapter.
Returning Values from Assignment
Using the assignment operator returns an overall value similar to other operators. If you write
$a + $b
the value of this expression is the result of adding the $a and $b variables together. Similarly,
you can write
$a = 0;
The value of this whole expression is zero.
This enables you to do things such as
$b = 6 + ($a = 5);
This will set the value of the $b variable to 11. This is generally true of assignments: The value
of the whole assignment statement is the value that is assigned to the left-hand operand.
When working out the value of an expression, parentheses can be used to increase the
precedence of a subexpression as we have done here. This works exactly the same way as in
mathematics.
PHP Crash Course
C
HAPTER 1
1
PHP CRASH
COURSE
27
03 7842 CH01 3/6/01 3:39 PM Page 27