Time: 00:00

PHP Intermediate Programming Quiz

Test your knowledge of PHP fundamentals

Total Marks: 30 | Time: 30 minutes

Student Information

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.";
?>
2. How do you retrieve data from a checkbox in a form using PHP?
[5 marks]
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";
}
?>
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";
}
?>
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]
Your quiz has been submitted successfully!