Time: 00:00
PHP Intermediate Programming Quiz
Test your knowledge of PHP fundamentals
Total Marks: 30 | Time: 30 minutes
Student Information
Name:
Surname:
1. What will the following code output?
[5 marks]
<?php
$name = "John";
$age = 25;
echo "My name is $name and I am $age years old.";
?>
My name is $name and I am $age years old.
My name is John and I am 25 years old.
Error: variables not defined
$name $age
2. How do you retrieve data from a checkbox in a form using PHP?
[5 marks]
$_GET['checkbox_name']
$_POST['checkbox_name']
$_REQUEST['checkbox_name']
All of the above
3. What will be the result of this if statement?
[5 marks]
<?php
$temperature = 15;
if ($temperature < 0) {
echo "Freezing";
} elseif ($temperature < 20) {
echo "Cold";
} else {
echo "Warm";
}
?>
Freezing
Cold
Warm
Error
4. What will this switch statement output when $color = "blue"?
[5 marks]
<?php
$color = "blue";
switch ($color) {
case "red":
echo "Color is red";
break;
case "blue":
echo "Color is blue";
break;
case "green":
echo "Color is green";
break;
default:
echo "Unknown color";
}
?>
Color is red
Color is blue
Color is green
Unknown color
5. Write PHP code that takes a user's grade from a form (field name: 'grade') and displays the corresponding remark using a switch statement:
A = Excellent, B = Good, C = Average, D = Poor, F = Fail
[5 marks]
6. Which PHP code correctly checks if a form was submitted using POST method?
[5 marks]
if ($_POST['submit']) { ... }
if ($_SERVER['REQUEST_METHOD'] == 'POST') { ... }
if (isset($_POST)) { ... }
if ($POST_METHOD == true) { ... }
Submit Quiz
Your quiz has been submitted successfully!