Prev | Current Page 166 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

Consider the outcomes of the
following examples:
$inv = 15; // Assign integer value 15 to $inv.
$oldInv = $inv--; // Assign $oldInv the value of $inv, then decrement $inv.
$origInv = ++$inv; // Increment $inv, then assign the new $inv value to $origInv.
As you can see, the order in which the increment and decrement operators are used
has an important effect on the value of a variable. Prefixing the operand with one of
these operators is known as a preincrement and predecrement operation, while postfixing
the operand is known as a postincrement and postdecrement operation.
Logical Operators
Much like the arithmetic operators, logical operators (see Table 3-9) will probably
play a major role in many of your PHP applications, providing a way to make decisions
based on the values of multiple variables. Logical operators make it possible to
direct the flow of a program and are used frequently with control structures, such as
the if conditional and the while and for loops.
Logical operators are also commonly used to provide details about the outcome of
other operations, particularly those that return a value:
file_exists("filename.txt") OR echo "File does not exist!";
One of two outcomes will occur:
??? The file filename.txt exists
??? The sentence ???File does not exist!??? will be output
Table 3-9. Logical Operators
Example Label Outcome
$a && $b AND True if both $a and $b are true
$a AND $b AND True if both $a and $b are true
$a || $b OR True if either $a or $b is true
$a OR $b OR True if either $a or $b is true
!$a NOT True if $a is not true
NOT $a NOT True if $a is not true
$a XOR $b Exclusive OR True if only $a or only $b is true
CHAPTER 3 ?–  PHP BASICS 93
Equality Operators
Equality operators (see Table 3-10) are used to compare two values, testing for
equivalence.


Pages:
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178