Đang chuẩn bị liên kết để tải về tài liệu:
PHP and MySQL Web Development - P14

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

PHP and MySQL Web Development - P14: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | 32 Chapter 1 PHP Crash Course Comparison Operators The comparison operators are used to compare two values. Expressions using these operators return either of the logical values true or false depending on the result of the comparison. The Equals Operator The equals comparison operator two equal signs enables you to test if two values are equal. For example we might use the expression a b to test if the values stored in a and b are the same.The result returned by this expression will be true if they are equal or false if they are not. It is easy to confuse this with the assignment operator.This will work without giving an error but generally will not give you the result you wanted. In general non-zero values evaluate to true and zero values to false. Say that you have initialized two variables as follows a 5 b 7 If you then test a b the result will be true.Why The value of a b is the value assigned to the left-hand side which in this case is 7.This is a non-zero value so the expression evaluates to true. If you intended to test a b which evaluates to false you have introduced a logic error in your code that can be extremely difficult to find. Always check your use of these two operators and check that you have used the one you intended to use. This is an easy mistake to make and you will probably make it many times in your programming career. Other Comparison Operators PHP also supports a number of other comparison operators. A summary of all the comparison operators is shown in Table 1.3. One to note is the new identical operator introduced in PHP 4 which returns true only if the two operands are both equal and of the same type. Table 1.3 PHP s Comparison Operators Operator Name equals identical not equal not equal less than Use a b a b a b a b a b Operators 33 Table 1.3 Continued Operator Name Use greater than a b less than or equal to a b greater than or equal to a b Logical Operators The logical operators are used to combine the results of logical conditions. .