1. Computing & Technology

Discuss in my forum

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.

©2012 About.com. All rights reserved.

A part of The New York Times Company.