2014-09-21

Nested if statement

Use the if....elseif...else statement to select one of several blocks of code to be executed.

Syntax

if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;


Example

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

<html>
<body>

<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>

</body>
</html>

Related Posts:

  • PHP If...Else Statementsv\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} Norma… Read More
  • IF statement.code .code-area{width:auto; min-height:25px; border-left:2px solid #d503a1; background:#fafafa; padding-left:3px; margin:-13px 0; margin-left:-2px; f… Read More
  • PHP Switch Statement Normal 0 false false false EN-US X-NONE X-NONE … Read More
  • Nested if statementUse the if....elseif...else statement to select one of several blocks of code to be executed. Syntax if (condition) code to be executed i… Read More

0 comments:

Post a Comment

Tools & Plugins

Blog Archive