Specifications
PHP supports logical AND, OR, XOR (exclusive or), and NOT.
The set of logical operators and their use is summarized in Table 1.4.
TABLE 1.4 PHP’s Logical Operators
Operator Name Use Result
! NOT !$b Returns true if $b is false, and vice versa
&& AND $a && $b Returns true if both $a and $b are true; other-
wise false
|| OR $a || $b Returns true if either $a or $b or both are true;
otherwise false
and AND $a and $b Same as &&, but with lower precedence
or OR $a or $b Same as ||, but with lower precedence
The and and or operators have lower precedence than the && and || operators. We will cover
precedence in more detail later in this chapter.
Bitwise Operators
The bitwise operators enable you to treat an integer as the series of bits used to represent it.
You probably will not find a lot of use for these in PHP, but a summary of bitwise operators is
shown in Table 1.5.
TABLE 1.5 PHP’s Bitwise Operators
Operator Name Use Result
& bitwise AND $a & $b Bits set in $a and $b are set in the result
| bitwise OR $a | $b Bits set in $a or $b are set in the result
~ bitwise NOT ~$a Bits set in $a are not set in the result,
and vice versa
^ bitwise XOR $a ^ $b Bits set in $a or $b but not in both are
set in the result
<< left shift $a << $b Shifts $a left $b bits
>> right shift $a >> $b Shifts $a right $b bits
PHP Crash Course
C
HAPTER 1
1
PHP CRASH
COURSE
31
03 7842 CH01 3/6/01 3:39 PM Page 31