11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 3 • <strong>PHP</strong> BASICSTable 3-10. Equality OperatorsExample 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 typeIt is a common mistake for even experienced programmers to attempt to test for equality using justone equal sign (e.g., $a = $b). Keep in mind that this will result in the assignment of the contents of $b to$a, thereby not producing the expected results.Comparison OperatorsComparison operators (see Table 3-11), like logical operators, provide a method to direct program flowthrough an examination of the comparative values of two or more variables.Table 3-11. Comparison OperatorsExample 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 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 –1Note that the comparison operators should be used only for comparing numerical values. Althoughyou may be tempted to compare strings with these operators, you will most likely not arrive at theexpected outcome if you do so. There is a substantial set of predefined functions that compare stringvalues; they are discussed in detail in Chapter 9.Bitwise OperatorsBitwise operators examine and manipulate integer values on the level of individual bits that make up theinteger value (thus the name). To fully understand this concept, you need at least an introductoryknowledge of the binary representation of decimal integers. Table 3-12 presents a few decimal integersand their corresponding binary representations.73

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!