?

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


?

Previous Page Page 4 of 5 Next Page

Control Structures

Control structures allow decision making, looping and other flow management.

Decision Making

If something is true then branch in one direction else branch in another.? In the following example, we execute one of three commands depending on the time of day.

PHP Code:


$date = date ("H");

echo "";

if ($date < 12) echo "Good Morning!";
else if ($date < 18) echo "Good Afternoon!";
else echo "Good Night!";

echo "";

?>

Web Browser Results:

Good Morning!

PHP Code:

Good Afternoon!

PHP Code:

Good Night!

date ("H")
This is a PHP function that returns the local time in 24 hour format. ?For more information on this and other PHP functions click here. ?The variable $date will contain a string ranging from "0" to "23". ?It is important to remember that this string can be treated like a number.

if, else if, else
If a condition equals true then execute this code. ?Therefore, in our example, if $date is less than 12 display the string "Good Morning!".?

For more information on decision making refer to the manual.

Previous Page Page 4 of 5 Next Page