It is a common mistake for even experienced programmers to attempt to test for
equality using just one equal sign (e.g., $a = $b). Keep in mind that this will result in
the assignment of the contents of $b to $a and will not produce the expected results.
Comparison Operators
Comparison operators (see Table 3-11), like logical operators, provide a method to
direct program flow through an examination of the comparative values of two or
more variables.
Note that the comparison operators should be used only for comparing numerical
values. Although you may be tempted to compare strings with these operators, you
will most likely not arrive at the expected outcome if you do so. There is a substantial
set of predefined functions that compare string values, which are discussed in detail
in Chapter 9.
Table 3-10. Equality Operators
Example Label Outcome
$a == $b Is equal to True if $a and $b are equivalent
$a != $b Is not equal to True if $a is not equal to $b
$a === $b Is identical to True if $a and $b are equivalent and $a and $b have
the same type
Table 3-11. Comparison Operators
Example Label Outcome
$a < $b Less than True if $a is less than $b
$a > $b Greater than True if $a is greater than $b
$a <= $b Less than or equal to True if $a is less than or equal to
$b
$a >= $b Greater than or equal to True if $a is greater than or
equal to $b
($a == 12) ? 5 : -1 Ternary If $a equals 12, return value is 5;
otherwise, return value is ??“1
94 CHAPTER 3 ?– PHP B ASICS
Bitwise Operators
Bitwise operators examine and manipulate integer values on the level of individual
bits that make up the integer value (thus the name).
Pages:
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179