Page 94 - Open Soource Technologies 304.indd
P. 94
Unit 6: Building Blocks of PHP
Notes
Operator Name Value
&&, and Logical AND The result of the logical AND
operation between the two
operands
||, or Logical OR The result of the logical OR
operation between the two
operands
xor Logical XOR The result of the logical XOR
operation between the two
operands
Short-Circuit Evaluation: When evaluating the logical and/or operators, you can often know
the result without having to evaluate both operands. For example, when PHP evaluates
0 && 1, it can tell the result will be false by looking only at the left operand, and it won’t continue
to evaluate the right one. This might not seem useful right now, but later on, we’ll see how we
can use it to execute an operation only if a certain condition is met.
6.1.3.5 Bitwise Operators
Bitwise operators: Perform an operation on the bitwise representation of their arguments. Unless
the arguments are strings, they are converted to their corresponding integer representation, and
the operation is then performed. In case both arguments are strings, the operation is performed
between corresponding character offsets of the two strings (each character is treated as an integer).
Operator Name Value
& Bitwise AND Unless both operands are strings,
the integer value of the bitwise
AND operation between the two
operands. If both operands are
strings, a string in which each
character is the result of a bitwise
AND operation between the two
corresponding characters in the
operands. In case the two operand
strings are different lengths, the
result string is truncated to the
length of the shorter operand.
| Bitwise OR Unless both operands are
strings, the integer value of the
bitwise OR operation between the
two operands. If both operands
are strings, a string in which each
bitwise character is the result of a
bitwise OR operation between the
two corresponding characters in
Contd...
LOVELY PROFESSIONAL UNIVERSITY 89