tailieunhanh - Giải pháp thiết kế web động với PHP - p 7

HOW TO WRITE PHP SCRIPTS } elseif ( second condition is true ) { // code to be executed if first condition fails // but second condition is true } else { // default code if both conditions are false } You can use as many elseif clauses in a conditional statement as you like. It s important to note that only the first one that equates to true will be executed; all others will be ignored, even if they re also true. This means you need to build conditional statements in the order of priority that you want them to. | HOW TO WRITE PHP SCRIPTS elseif second condition is true code to be executed if first condition fails but second condition is true else default code if both conditions are false You can use as many elseif clauses in a conditional statement as you like. It s important to note that only the first one that equates to true will be executed all others will be ignored even if they re also true. This means you need to build conditional statements in the order of priority that you want them to be evaluated. It s strictly a first-come first-served hierarchy. Although elseif is normally written as one word you can use else if as separate words. An alternative decision-making structure the switch statement is described in the second half of this chapter. Making comparisons Conditional statements are interested in only one thing whether the condition being tested equates to true. If it s not true it must be false. There s no room for half-measures or maybes. Conditions often depend on the comparison of two values. Is this bigger than that Are they both the same And so on. To test for equality PHP uses two equal signs like this if status administrator send to admin page else refuse entry to admin area Don t use a single equal sign in the first line status administrator . Doing so will open the admin area of your website to everyone. Why Because this automatically sets the value of status to administrator it doesn t compare the two values. To compare values you must use two equal signs. It s an easy mistake to make but one with potentially disastrous consequences. Size comparisons are performed using the mathematical symbols for less than and greater than . Let s say you re checking the size of a file before allowing it to be uploaded to your server. You could set a maximum size of 50kB like this 1 kilobyte 1024 bytes if bytes 51200 display error message and abandon upload else continue upload You can test for multiple conditions simultaneously. Details are in the second half of

TỪ KHÓA LIÊN QUAN