25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

20 ” <strong>PHP</strong> Basics<br />

4,294,967,296—which, incidentally, will now be a float because such a number cannot<br />

be represented using a signed 32-bit integer.<br />

Assignment Operators<br />

Given the creativity that we have shown in the naming conventions to this point,<br />

you’ll probably be very surprised to hear that assignment operators make it possible<br />

to assign a value to a variable. The simplest assignment operator is a single equals<br />

sign, which we have already seen in previous examples:<br />

$variable = ’value’;<br />

// $variable now contains the string ’value’<br />

In addition, it is possible to combine just about every other type of binary arithmetic<br />

and bitwise operator with the = sign to simultaneously perform an operation on a<br />

variable and reassign the resulting value to itself:<br />

$variable = 1;<br />

// $variable now contains the integer value 1<br />

$variable += 3;<br />

/*<br />

$variable now contains the integer 4<br />

*/<br />

In this example, we pair the addition operator (the plus sign) with the equals sign to<br />

add the existing value of $variable to the right operand, the integer 3. This technique<br />

can be used with all binary arithmetic and bitwise operators.<br />

Referencing Variables<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)<br />

By default, assignment operators work by value—that is, they copy the value of an<br />

expression on to another. If the right-hand operand happens to be a variable, only<br />

its value is copied, so that any subsequent change to the left-hand operator is not<br />

reflected in the right-hand one. For example:<br />

$a = 10;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!