Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Web Publishing with PHP and FileMaker 9- P4:On the other hand, it would drive me nuts if you bought this book only to discover that it didn’t address your needs. In the spirit of customer satisfaction, please read the following introduction to get a sense of where I’m coming from, and whether you might get some good use out of this book. | Basic PHP Syntax 35 It would be nice to be able to say that you should always just use single quotes or always use double quotes. However you will probably find one or the other to be useful in certain situations. Conditional Structures You won t get far in PHP before you need to have your page make some decisions on its own. That s where conditional structures come into play. There are many conditional structures some even have alternate formats. I am going to focus on the one that I feel is the most useful in the widest number of cases the if else and elseif constructs. php name Susannah if name Susannah echo Yep it s her else echo Nope it s not her outputs Yep it s her 3 I start by assigning a value to the name variable. Then I open up an If block and check to see if name equals Susannah. If it does the code between the first set of curly braces is executed. Otherwise the code between the second set of curly braces after the else would trigger. Unlike statements the lines of a control structure do not need to be terminated by a semicolon. Take special note of the fact that the equivalency operator in the expression is a double equal sign. This is very important. Inadvertently using a single equal sign is a frequent source of bugs. CAUTION Gotcha If I had only used one equal sign the script wouldn t fail it just wouldn t perform as desired. It would reassign Susannah to the name variable and the if statement would evaluate to TRUE every time. This is confusing at first so for now just remember to make sure you use the double equal sign in your if statements You can nest if statements but it s often easier to use the elseif construct like so php name Susannah if name Lily echo Hi Lily elseif name Matt echo Hi Matt else 36 CHAPTER 3 Introduction to PHP echo Who s there outputs Who s there You can include as many elseif blocks as you want. The else block at the end of this example is a catchall that will handle any cases that evaluated to FALSE in all of the .