tailieunhanh - php solutions dynamic web design made easy phần 3

mà không có sự cho phép trước bằng văn bản của chủ sở hữu quyền tác giả và nhà xuất bản. in và bị ràng buộc tại Hoa Kỳ của Mỹ đăng kí nhãn hiệu tên có thể xuất hiện trong cuốn sách này. Thay vì sử dụng một biểu tượng thương hiệu với tất cả sự xuất hiện của một tên đã đăng ký nhãn hiệu, | HOW TO WRITE PHP SCRIPTS so testing stops as soon as one turns out to be false. Similarly when using only one condition needs to be fulfilled so testing stops as soon as one turns out to be true. a 10 b 25 if a 5 b 20 returns true if a 5 b 30 returns true b never tested The implication of this is that when you need all conditions to be met you should design your tests with the condition most likely to return false as the first to be evaluated. When you need just one condition to be fulfilled place the one most likely to return true first. If you want a particular set of conditions considered as a group enclose them in parentheses. if a 5 a 8 b 20 b 40 3 PHP also uses AND in place of and OR in place of . However they aren t exact equivalents. To avoid problems it s advisable to stick with and II. Using the switch statement for decision chains The switch statement offers an alternative to if. else for decision making. The basic structure looks like this switch variable being tested case valuel statements to be executed break case value2 statements to be executed break default statements to be executed The case keyword indicates possible matching values for the variable passed to switch . When a match is made every subsequent line of code is executed until the break keyword is encountered at which point the switch statement comes to an end. A simple example follows switch myVar case 1 echo myVar is 1 break case apple echo myVar is apple break default echo myVar is neither 1 nor apple 79 PHP SOLUTIONS DYNAMIC WEB DESIGN MADE EASY The main points to note about switch are as follows The expression following the case keyword must be a number or a string. You can t use comparison operators with case. So case 100 isn t allowed. Each block of statements should normally end with break unless you specifically want to continue executing code within the switch statement. You can group several instances of the case keyword together to apply the same block of code to them. If no .

TỪ KHÓA LIÊN QUAN