We're already familiar with the concepts of the control statements as we learned in JavaScript. They behave basically the same, but since they are in different languages, the syntax can be a little different.

The following example will output "Have a nice weekend!" if the current day is Friday, otherwise it will output "Have a nice day!":

<html>
<body><?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";
?></body>
</html>

If more than one line should be executed when a condition is true, the lines should be enclosed within curly braces:

<html>
<body><?php
$x=10;
if ($x==10) // notice one = sign assigns a value to a variable, two compares values.
{
echo "Hello<br />";
echo "Good morning<br />";
}
?></body>
</html>

(from w3schools.com)

Switch

Table of Contents