3.1 PHP Operators - Exercises
Started: Feb 5 at 7:21pm
Quiz Instructions
Question 1 1 pts
Multiply 10 with 5, and output the result.
Question 2 1 pts
Divide 10 by 2, and output the result.
echo 10 2;
Question 3 1 pts
Use the correct comparison operator to check if $a is equal to $b.
var_dump($a $b);
Question 4 1 pts
Use the correct comparison operator to check if $a is NOT equal to $b.
var_dump($a $b);
3.2 PHP If...Else - Exercises
Question 1 1 pts
Output "Hello World" if $a is greater than $b.
$a = 50;
$b = 10;
> {
echo "Hello World";
}
Question 2 1 pts
Output "Hello World" if $a is NOT equal to $b.
$a = 50;
$b = 10;
($a $b) {
echo "Hello World";
}
Question 3 1 pts
Output "Yes" if $a is equal to $b, otherwise output "No".
$a = 50;
$b = 10;
($a == $b) {
echo "Yes";
} {
echo "No";
}
Question 4 1 pts
Output "1" if $a is equal to $b, print "2" if $a is greater than $b, otherwise output "3".
$a = 50;
$b = 10;
($a == $b) {
echo "1";
} ($a > $b) {
echo "2";
} {
echo "3";
}
3.3 PHP Switch - Exercises
Started: Feb 6 at 12:59pm
Question 1 1 pts
Create a switch statement that will output "Hello" if $color is "red", and "welcome" if $color is "green".
($color) {
"red":
echo "Hello";
break;
"green":
echo "Welcome";
break;
}
Question 2 1 pts
Add a section that will output "Neither" if $color is neither "red" nor "green".
switch ($color) {
case "red":
echo "Hello";
break;
case "green":
echo "Welcome";
break;
default: (answer)
echo "Neither";
}
3.4 PHP Loops - Exercises
Started: Feb 7 at 11:45pm
Question 1 1 pts
Output $i as long as $i is less than 6.
$i = 1;
($i < 6)
echo $i;
$i++;
Question 2 1 pts
Output $i as long as $i is less than 6.
$i = 1;
{
echo $i;
$i++;
} ($i < 6);
Question 3 1 pts
Create a loop that runs from 0 to 9.
for ($i = 0; $i < 10;
$i++) {
echo $i;
}
Question 4 1 pts
Loop through the items in the $colors array.
$colors = array("red", "green", "blue", "yellow");
($colors $x) {
echo $x;
}
3.5 PHP Functions - Exercises
Started: Feb 8 at 3:25pm
Question 1 1 pts
Create a function named myFunction.
function myFunction(){
echo "Hello World!";
}
Question 2 1 pts
Call (execute) a function named myFunction.
function myFunction() {
echo "Hello World!";
}
myFunction();
Question 3 1 pts
Inside a function with two parameters, print the first parameter.
function myFunction($fname, $lname) {
echo $fname;
}
Question 4 1 pts
Let the function return the second value.
function myFunction($fname, $lname) {
return $lname;
}