If, Elseif Statements & Logical Operators 1. Create a file named: Logical1.php i
ID: 3550615 • Letter: I
Question
If, Elseif Statements & Logical Operators
1. Create a file named: Logical1.php in your text editor.
2. Create an if-elseif-else statement that satisfies the following for the variable: $day (simple string, NOT date() function!), then make any one (1) of the statements true and display it:
o If Wednesday echo back Hump Day!
o If Friday echo TGIF!!!
o Otherwise echo Enjoy Your Day!
3. Assign two variables ($num1, $num2) a different numeric value each. Using the && and || logical operators, create an if-elseif-else statement (using comparison operators of your choice) that makes the OR (||) statement true. (Remember, in the OR statement, only ONE part has to be true, not BOTH!)
4. Using the correct comparison operators, create a series of if-else statements that make the following true:
o A is greater than B
o C is less than or equal to D
o E is equal to F
o G is not equal to H
5. Note: Use the following sample code to create a BR (carriage return line feed) between the results: if ($a > $b) {echo "A is Greater Than B <br />"; }
6. Here is a sample of what your output should look like
Enjoy Your Day!
X<20 or Y>32
A is greater than B.
C is less than or equal to D.
E is equal to F.
G is not equal to H.
Explanation / Answer
<?php
$day="Monday"; /*U can change monday to which ever day you need*/
if($day == "Wednesday")
{
echo "Hump Day! </br>";
}
else if($day=="Friday")
{
echo "TGIF </br>";
}
else
{
echo "Enjoy Your Day! </br>";
}
$num1=25;
$num2=45;
if($num1%5==1 && $num2==45 )
{
echo "$num1%5==1 AND $num2==45 </br>";
}
else if($num1>20 || $num2<40)
{
echo "$num1>20 or $num2<40 </br>";
}
else
{
echo "All Condition false";
}
$A=10;
$B=8;
$C=9;
$D=33;
$E=22;
$F=22;
$G=11;
$H=12;
if($A>$B)
{
echo"A is greater than B </br>";
}
else
{
echo"A is less than B </br>";
}
if($C<=$D)
{
echo"C is less than or equal to D </br>";
}
else
{
echo " C is not less than or equal to D </br>";
}
if($E==$F)
{
echo "E is equal to F </br>";
}
else
{
echo "E is not equal to F </br>";
}
if($G==$H)
{
echo "G is equal to H </br>";
}
else
{
echo "G is not equal to H </br>";
}
?>