Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

See Table 2.8 for an example of a bitwise operation, which shows that (12 & 10) == 8.
Matching bits are operated on. In the rightmost position 0 and 0 are operated on with a
bitwise AND. The result is 0 , so a 0 is put in this position of the result.


Bitwise operators are very useful in C, from which PHP takes inspiration, but you rarely
will need to use them in a PHP script. You will find some functions in the reference
chapters (8 through 14) that use bitfields.


Table 2.7. Bitwise Operators
Operator Operation Performed

& (^) And
| (^) Or
^ (^) Exclusive Or
~ (^) One's Complement or NOT




(^) Shift all bits to the right
<< (^) Shift all bits to the left
Table 2.8. Bitwise AND of 12 and 10
1 1 0 0 (12)
& 1 0 1 0 (10)
1 0 0 0 (8)
Miscellaneous Operators
There are operators that don't fit into any of the previous categories: the concatenation
operator, the variable marker, the reference operator, and others. Table 2.9 lists them.
The concatenation operator is similar to the addition operator except that it joins two
strings. I find this operator indispensable. When issuing a print, it is convenient to
concatenate several strings. I also use the concatenation operator to build database
queries. Listing 2.8 is an example of doing this.
When variables were discussed earlier, it was shown that a dollar sign always precedes
the name of a variable. This is true whether the variable is global, local, or a function
argument. The operator can be taken to mean, "Use the value stored in the named
variable." If an ampersand precedes the dollar sign, it changes the meaning of the
operation to be, "Use the memory set aside to store the data for the variable." This is
similar to the new operator in C++ and other languages. This subtle difference is useful in
declaring and calling functions.
Table 2.9. Miscellaneous Operators
Operator Operation Performed
. (^) Concatenate



Free download pdf