If Else Statement
Say you wanted a certain message to be displayed on Monday, and another on Saturday, you can use this PHP code to do so.
Start off with this:
<?php
?>
We’ll add a variable named “D” for day:
$d=date("D");
And then this:
if ($d=="Fri") echo "Yay! It's the weekend!";
“Fri” is the day that you’d like the text “Yay! It’s the weekend!” to show (Change “Fri” to any other day of the week. You can also change the “Have a nice weekend!” to whatever). Now, we need the.. ‘Else’:
else
echo "Have a nice day :)";
The “Have a nice day :)” is what’ll be displayed if it’s not Friday. Again, you can change this.
Now, say if you wanted a different message to display on a Wednesday. You just add another ‘If’ except with ‘else’ in-front:
elseif ($d=="Wed") echo "Half-way through the week!";
Here’s my final code:
<?php
$d=date("D");
if ($d=="Fri") echo "Yay! It's the weekend!";
elseif ($d=="Wed") echo "Half-way through the week!";
else
echo "Have a nice day :)";
?>
Simple! Example: