Chapter 6. Control Structures

I l @ ve RuBoard

Now that I've covered the basics of the variable types (aside from arrays, which will be covered in Chapter 7, Using Arrays), I can get into the real meat of programming ”control structures (i.e., conditionals and loops ). In the process, I'll finish the discussion of the various operators PHP uses. (I've already covered arithmetic and assignment in the variable chapters.)

Conditional structures are a staple of programming languages. They allow you to establish a parameter and then perform an action based upon the results of that parameter. This gives you the ability to make your Web sites even more dynamic. For example, if the time of day is before noon, you can greet the user with a "Good Morning!" If it is after noon, you'll print "Good Afternoon!" There are two general conditionals ” if and switch ” in PHP that you'll begin using in this chapter.

While I am discussing if conditionals, I'll introduce two last categories of operators ”comparison and logical. You'll commonly use these in your conditionals along with the PHP concepts of TRUE and FALSE.

Finally, you'll begin programming with loops, which allow you to repeat an action for a specified number of iterations. Loops can save you programming time and help you get the most functionality out of arrays, as you'll see in the next chapter. PHP supports two major loop constructs ” while (and its counterpart do while ) and for.

I l @ ve RuBoard


PHP for the World Wide Web (Visual QuickStart Guide)
PHP for the World Wide Web (Visual QuickStart Guide)
ISBN: 0201727870
EAN: 2147483647
Year: 2001
Pages: 116
Authors: Larry Ullman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net