PHP for Beginners: final quiz

Ten questions covering the whole PHP for Beginners course.

  • Beginner
  • 10 questions

10 questions. Pass mark 70%.

  1. Question 1 of 10 Which command starts PHP’s built-in web server on port 8000?
  2. Question 2 of 10 What does this print?
    PHP
    $a = '5';
    $b = 5;
    var_dump($a === $b);
  3. Question 3 of 10 Which of these are valid variable names in PHP?

    Select all that apply.

  4. Question 4 of 10 What is the output?
    PHP
    $name = 'Sam';
    echo "Hello, {$name}!";
    echo 'Hello, {$name}!';
  5. Question 5 of 10 Which expression returns ‘pass’ when $score is 70 or more, and ‘fail’ otherwise, without any if statement?
  6. Question 6 of 10 How many times does this loop print a line?
    PHP
    for ($i = 0; $i < 5; $i += 2) {
        echo $i, PHP_EOL;
    }
  7. Question 7 of 10 What does count(['a' => 1, 'b' => 2, 'c' => 3]) return?
  8. Question 8 of 10 What does this function return for add(2, 3)?
    PHP
    function add(int $a, int $b = 10): int
    {
        return $a + $b;
    }
  9. Question 9 of 10 You print a name submitted in a form back to the page. Which is safe?
  10. Question 10 of 10 Which statement stops the script with a fatal error if the file is missing, and never loads it twice?