PHP mock tests
Test yourself on the whole course, against the clock: questions from every module, then coding problems you solve and run right here. Your score comes at the end, with every answer explained.
Each mock test has 12 questions drawn from the lessons, and 45 minutes on the clock, which keeps running if you reload. Questions are worth a point each. Score 60% or more to pass; your best score is kept.
- 01Mock test 112 questions · 45 minutes · 12 points
- 02Mock test 212 questions · 45 minutes · 12 points
- 03Mock test 312 questions · 45 minutes · 12 points
Part A · 12 questions
- Why is $nums = sort($nums); a bug?
- What does array_map(fn($x) => $x * 2, [1, 2, 3]) return?
- Inside a transaction, what does rollBack() do?
- What is the result of 7 / 2 in PHP?
- What does a prepared statement protect against?
- How do you call price(float $amount, float $tax = 0.18, string $currency = "INR") with amount 100 and currency "USD", keeping the default tax?
- How do you read $config["mode"] with "live" as the default when the key is missing?
- What does ?string mean as a return type?
- Which line appends text to $s?
- $n = "Leo"; What does echo 'Hi $n'; print?
- What is the main way match differs from switch in comparing values?
- What does $_GET["page"] ?? 1 give when there is no page parameter?
Part A · 12 questions
- Which operator joins two strings in PHP?
- What type is $_POST["age"] when someone types 21?
- Why pass user input through htmlspecialchars before printing it?
- After unset($arr[0]) on [10, 20, 30], what is the first index?
- Why compare strpos($s, "x") !== false rather than != false?
- Why use JSON_THROW_ON_ERROR when decoding?
- A form field is named "email" and the form uses method="post". Where does PHP put its value?
- Which function sorts an associative array by its values, highest first, keeping the keys?
- Why wrap array_filter in array_values?
- How do you loop over an associative array and get both keys and values?
- How does an arrow function differ from an anonymous function?
- What is the result of 5 === "5" in PHP?
Part A · 12 questions
- What does json_encode(["a" => 1, "b" => 2]) produce?
- Where does PHP code run?
- Which of these values is falsy in PHP?
- What does 5 === "5" evaluate to?
- What does public function __construct(public string $name) {} do?
- Why call unset($p) after foreach ($arr as &$p)?
- What happens when no arm of a match expression matches and there is no default?
- Which line is safe when $email comes from a form?
- Which character must every PHP variable name start with?
- What does echo 'Hi $name'; print, if $name is "Leo"?
- Which operator joins two strings in PHP?
- What happens when you assign a new value to a readonly property after construction?