Page 92 - Open Soource Technologies 304.indd
P. 92
Unit 6: Building Blocks of PHP
Notes
/ Division The quotient of the two operands.
% Modulus Both operands are converted to integers. The result
is the remainder of the division of the first operand
by the second operand.
Concatenation Operator (.) The concatenation operator concatenates two strings. This operator
works only on strings; thus, any non-string operand is first converted to one.
The following example would print out “The year is 2000”:
$year = 2000;
print “The year is “ . $year;
The integer $year is internally converted to the string “2000” before it is concatenated with the
string’s prefix, “The year is”.
6.1.3.2 Assignment Operators
Assignment operators enable you to write a value to a variable. The first operand (the one on
the left of the assignment operator or l value) must be a variable. The value of an assignment
is the final value assigned to the variable; for example, the expression $var = 5 has the value 5
(and assigns 5 to $var).
In addition to the regular assignment operator =, several other assignment operators are
composites of an operator followed by an equal sign. These composite operators apply the
operator taking the variable on the left as the first operand and the value on the right (the r
value) as the second operand, and assign the result of the operation to the variable on the left.
For example:
$counter += 2; // This is identical to $counter = $counter + 2;
$offset *= $counter;// This is identical to $offset = $offset *
→ $counter;
The following list show the valid composite assignment operators:
+=, -=, *=, /=, %=, ^=, .=, &=, |=, <<=, >>=
By-Reference Assignment Operator PHP enables you to create variables as aliases for other
variables. You can achieve this by using the by-reference assignment operator =&. After a variable
aliases another variable, changes to either one of them affects the other.
For example:
$name = “Judy”;
$name_alias =& $name;
$name_alias = “Jonathan”;
print $name;
LOVELY PROFESSIONAL UNIVERSITY 87