Yahoo web hosting - Control andFunctionsIt s difficult to write interesting programs if
Control andFunctionsIt s difficult to write interesting programs if you can t make thecourse of program execution depend on anything. In a weak sense, the behavior of code that prints variables depends on the variablevalues, but that is as exciting as filling out a template. As program- mers, we want programs that react to something (the world, the timeof day, user input, or the contents of a database) by doing somethingdifferent. This kind of program reaction requires a control structure,which indi- cates how different situations should lead to the execution of differ- ent code. In Chapter 5, we informally used the ifcontrol structurewithout really explaining it; in this chapter, we lay out every kind ofcontrol structure offered by PHP and study their workings in detail. Experienced C programmers: Of all the features in PHP, control isprobably the most reliably C-like all the structures you are usedto are here, and they work the same way. The two broad types of control structures we will talk about arebranchesand loops.A branch is a fork in the road for a program s exe- cution depending on some test or other, the program goes eitherleft or right, possibly following a different path for the rest of the pro- gram s execution. A loop is a special kind of branch where one of theexecution paths jumps back to the beginning of the branch, repeatingthe test and possibly the body of the loop. Before we can make interesting use of control structures, however, we have to be able to construct interesting tests. We ll start from thevery simplest of tests, working our way up from the constants TRUEand FALSEand then move on to using these tests in more compli- cated code. Any real programming language has some kind of capability for proce- dural abstraction a way to name pieces of code so that you can usethem as building blocks in writing other pieces of code. Some script- ing languages lack this capability, and we can tell you from our ownsorrowful experience that complex server-side code can quicklybecome unmanageable without it. PHP s mechanism for this kind of abstraction is the function.Thereare really two kinds of functions in PHP those that have been builtinto the language by the PHP developers and those defined by indi- vidual PHP programmers. Note66CHAPTER …In This ChapterBoolean expressionsBranchingLoopingTerminating executionExceptionsUsing functionsFunction documentationDefining your ownfunctionsFunctions and variablescopeFunction scope …
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.