Elseif Conditions in PHP

by Hiroshi on June 19, 2008

in Conditions, Else, Elseif, if, PHP Basics

This example is based on if elseif and else. It is as simple as telling script to do something if it finds A, If A is not present then look for B and if B is found then do something else. But if A and B are not found and there is something other then do anything else for all other cases.

An if/else statement is great if you only need to check for one condition. However, what would you do if you wanted to check whether its a morning, evening or afternoon. Consider following example.

$hour = date("H");
if ($hour < 12)
  echo "Good morning";
  elseif ($hour < 17)
     echo "Good afternoon";
         echo "Good evening";

Related Posts

Previous post:

Next post: