Msn web hosting - HOW TO WRITE PHP SCRIPTS As the next
HOW TO WRITE PHP SCRIPTS As the next section explains, PHP makes decisions on the basis of whether something eval uates to true or false. Putting quotes around false has surprising consequences. The fol lowing code: $OK = false; does exactly what you expect: it makes $OK false. Now take a look at this: $OK = ‘false’; This does exactly the opposite of what you might expect: it makes $OK true! Why? Because the quotes around false turn it into a string, and PHP treats strings as true. (There s a more detailed explanation in The truth according to PHP in the second half of this chapter.) The other thing to note about true, false, and null is that they are case-insensitive. The following examples are all valid: $OK = TRUE; $OK = tRuE; $OK = true; So, to recap: PHP treats true, false, and null as special cases. Don t enclose them in quotes. They are case-insensitive. Making decisions Decisions, decisions, decisions . . . Life is full of decisions. So is PHP. They give it the ability to display different output according to circumstances. Decision making in PHP uses con ditional statements. The most common of these uses if and closely follows the structure of normal language. In real life, you may be faced with the following decision (admittedly not very often if you live in Britain): If the weather’s hot, I’ll go to the beach. In PHP pseudo-code, the same decision looks like this: if (the weather’s hot) { I’ll go to the beach; } The condition being tested goes inside parentheses, and the resulting action goes between curly braces. This is the basic decision-making pattern: if (condition is true) { // code to be executed if condition is true }
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.