Page 80 - Beginning PHP 5.3
P. 80

Part II: Learning the Language
                   which means:  “ Assign the value  8.23  to  $test_var , then assign the result of that expression ( 8.23 ) to
                   $another_var . ”  So both  $test_var  and  $another_var  now contain the value  8.23 .

                  The equals sign (  = ) can be combined with other operators to give you a  combined assignment operator  that
                 makes it easier to write certain expressions. The combined assignment operators (such as +=,  – =, and so
                 on) simply give you a shorthand method for performing typical arithmetic operations, so that you don ’ t
                 have to write out the variable name multiple times. For example, you can write:
                    $first_number += $second_number;

                  rather than:

                    $first_number = $first_number + $second_number;
                   This also works for other kinds of operators. For example, the concatenation operator (described later
                 in this chapter) can be combined with the equals sign (as   .= ), causing the value on the right side to be
                appended to the existing value on the left, like this:

                    $a = “Start a sentence “;
                    $b = “and finish it.”;
                    $a .= $b;                 // $a now contains  “ Start a sentence and finish it. ”

                   The main arithmetic, string, and bitwise operators support combination in this fashion; find out more at
                                                                                .
                   http://www.php.net/manual/en/language.operators.assignment.php
                  Bitwise Operators
                   PHP ’ s bitwise operators let you work on the individual bits within integer variables. Consider the
                 integer value 1234. For a 16 - bit integer, this value is stored as two bytes: 4 (the most significant byte) and
                 210 (the least significant). 4 * 256 + 210 = 1234.

                   Here ’ s how those two bytes look as a string of bits:
                    00000100 11010010

                   A bit with a value of 1 is said to be  set , whereas a bit with a value of 0 is  unset  (or not set).

                   PHP ’ s bitwise operators let you manipulate these bits directly, as shown in the following table.
                 Each example includes both decimal values and their binary equivalents, so you can see how the bits
                 are altered:



                      Operator        Description                 Example
                        &   (And)         Only bits set in both values       14  &  3 = 2
                                  are set in the result        00001110  &  00000011 = 00000010
                       |  (Or)         Bits set in either value are set       14 | 3 = 15
                                  in the result                   00001110 | 00000011 = 00001111





              42





                                                                                                      9/21/09   8:51:24 AM
          c03.indd   42                                                                               9/21/09   8:51:24 AM
          c03.indd   42
   75   76   77   78   79   80   81   82   83   84   85