One of the main reasons for using scripting languages such as PHP is to build logic and intelligence into the creation and deployment of web based data. In order to be able to build logic into PHP based scripts, it is necessary for the script to be able to make decisions and repeat tasks based on specified criteria.
For example, it may be necessary to repeat a section of a script a specified number of times, or perform a task only if one or more conditions are found to be true (i.e . only let the user log in if a valid passowrd password has been provided).
In programming terms this is known as ''flow control and looping''. In the simplest terms this involves some standard scripting structures provided by languages such as PHP to control the logic and overal overall behavior of a script. Each of these structures provides a simple and intuitive way to build intelligence into scripts. These PHP structures can be broken down into a number of categories as follows:
'''Conditional Statements'''
'''switch Statements'''
In this chapter we will explore each of these categories in turn and create some examples that demsonstrate demonstrate how to implement these mechanisms.
== PHP Conditional Statements ==
Just about everything in life revolves around decisions. We wouldn't get very far through the day if we weren't able to decide what to wear, what to eat and which roads to traverse on the way to work. Similarly computers would be of little use without some innate ability to evaluate choices and make decisions. If all we were able to do was provide a computer with a set of instructions that simply followed one after the other with no ability to make choices based on specific criteria, none of the software we have today would exist.
Exception encountered, of type "Error"
[e5e31cb1] /index.php/Special:MobileDiff/7768 Error from line 434 of /home/techotopia/includes/diff/DairikiDiff.php: Call to undefined function each()
Backtrace:
#0 /home/techotopia/includes/diff/DairikiDiff.php(544): DiffEngine->diag()
#1 /home/techotopia/includes/diff/DairikiDiff.php(344): DiffEngine->compareSeq()
#2 /home/techotopia/includes/diff/DairikiDiff.php(227): DiffEngine->diffLocal()
#3 /home/techotopia/includes/diff/DairikiDiff.php(721): DiffEngine->diff()
#4 /home/techotopia/includes/diff/DairikiDiff.php(859): Diff->__construct()
#5 /home/techotopia/includes/diff/DairikiDiff.php(980): MappedDiff->__construct()
#6 /home/techotopia/extensions/MobileFrontend/includes/diff/InlineDiffFormatter.php(99): WordLevelDiff->__construct()
#7 /home/techotopia/includes/diff/DiffFormatter.php(140): InlineDiffFormatter->changed()
#8 /home/techotopia/includes/diff/DiffFormatter.php(82): DiffFormatter->block()
#9 /home/techotopia/extensions/MobileFrontend/includes/diff/InlineDifferenceEngine.php(117): DiffFormatter->format()
#10 /home/techotopia/includes/diff/DifferenceEngine.php(797): InlineDifferenceEngine->generateTextDiffBody()
#11 /home/techotopia/includes/diff/DifferenceEngine.php(728): DifferenceEngine->generateContentDiffBody()
#12 /home/techotopia/extensions/MobileFrontend/includes/specials/SpecialMobileDiff.php(241): DifferenceEngine->getDiffBody()
#13 /home/techotopia/extensions/MobileFrontend/includes/specials/SpecialMobileDiff.php(135): SpecialMobileDiff->showDiff()
#14 /home/techotopia/extensions/MobileFrontend/includes/specials/MobileSpecialPage.php(53): SpecialMobileDiff->executeWhenAvailable()
#15 /home/techotopia/includes/specialpage/SpecialPage.php(384): MobileSpecialPage->execute()
#16 /home/techotopia/includes/specialpage/SpecialPageFactory.php(553): SpecialPage->run()
#17 /home/techotopia/includes/MediaWiki.php(281): SpecialPageFactory::executePath()
#18 /home/techotopia/includes/MediaWiki.php(714): MediaWiki->performRequest()
#19 /home/techotopia/includes/MediaWiki.php(508): MediaWiki->main()
#20 /home/techotopia/index.php(41): MediaWiki->run()
#21 {main}