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.

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

$string2 = "baz";<br />

// $string2 now contains the value ’baz’<br />

$string .= $string2;<br />

// After concatenating the two variables, we end up with ’foobarbaz’<br />

echo $string;<br />

// Displays ’foobarbaz’<br />

It is important to remember that this is not just the proper way to concatenate two<br />

strings using an operation—it is the only way. Using the addition operator will result<br />

in the two strings being first converted to numeric values, and then added together<br />

(thus also yielding a numeric value).<br />

Bitwise Operators<br />

Bitwise operators allow you to manipulate bits of data. All these operators are designed<br />

to work only on integer numbers—therefore, the interpreter will attempt to<br />

convert their operands to integers before executing them.<br />

The simplest bitwise operator is binary not, which negates all the bits of an integer<br />

number:<br />

$x = 0;<br />

echo ~$x; // will output -1<br />

A group of binary bitwise operators is used to perform basic bit manipulation by<br />

combining the bits of its two operands in various ways:<br />

& Bitwise AND. The result of the operation will be a value whose bits are<br />

set if they are set in both operands, and unset otherwise.<br />

| Bitwise OR. The result of the operation will be a value whose bits are<br />

set if they are set in either operand (or both), and unset otherwise.<br />

ˆ Bitwise XOR (exclusive OR). The result of the operation will be a value<br />

whose bits are set if they are set in either operand, and unset<br />

otherwise.<br />

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

These operations are all quite straightforward—with the possible exception of the<br />

exclusive OR, which may look odd at first sight. In reality, its functionality is quite

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

Saved successfully!

Ooh no, something went wrong!