Visit the Official PHP Website

Search this Site

PHP Programming

By James N Hitz

Decision-Making Control Structures

These are constructs that execute a different segment of code if a certain condition prevails, and another segment of code if a different condition prevails. It makes a decision.

Look at this phrase:

"If it's cold you put on a jacket and if it's warm you put on a t-shirt"

... we always make decisions at all times in our lives. To make the right decisions in life we undoubtedly require intelligence. PHP is no different. In this Lesson we try and make "intelligent" PHP scripts that will be able to decide what to put on.

So what's it gonna be: a jacket or a t-shirt?

That's not the real question though. The question is... "How will the computer be able to decide? Where will a PHP script get that kinda' wisdom?"

It all boils down to two things: true or false. Let's see...

"You wake up in the morning peek out of the window and you ask yourself: 'Is it cold?' If the answer is 'yes' (true) you put on a jacket. If the answer is 'no' (false) you put on a t-shirt"

... true or false? That's all it is.

PHP's code contructs that control decision making include:

  1. if
  2. if... else
  3. if... elseif...
  4. switch

<< Beyond the Statement Block | The if Control Structure >>

JamHitz Productions