1. Home
  2. Computing & Technology
  3. PHP / MySQL

IF - Using IF in PHP
Using IF to make choices in your PHP program

By , About.com Guide

When your computer program needs to make a decision, its form of thinking is limited to Boolean logic. Basically the program can look at a statement and decide if it is true or false. All larger decisions are based on a series of these true or false questions. Let's say a website about dogs asks you if you have a dog. If the answer is yes, it shows you the sales on dog supplies. For everyone else it shows a list of dogs available to adopt. This can be done by using if and else.

Perhaps you want to give the visitors more than just two options. You might ask if they have a dog, a cat, are looking to adopt, or are just shopping for gifts. You could use a series of if-elseif to direct them to the right place, but you're probably better off using switch. Switch lets you set a corse of action for a number of different possible inputs. Just remember that this too is only thinking in true or false... switch checks each possible case as true or false and then executes based on that decision.

More PHP / MySQL Quick Tips
Explore PHP / MySQL
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. IF - Using IF and Else for PHP decisions

©2009 About.com, a part of The New York Times Company.

All rights reserved.