exercises and solutions
Hints policy
Hints should restart a learner's reasoning without pasting the solution. Add them when a likely sticking point is not the skill being tested.
Order hints from least revealing to most specific: point back to the concept, name the relevant PHP API or boundary, then suggest the shape of the next step. If a hint needs to introduce an API that the article never taught, fix the lesson or narrow the task.
Practical Example
<?php
declare(strict_types=1);
$hints = [
'first' => 'Think about the input shape.',
'second' => 'Try a foreach loop.',
'final' => 'Compare your output with the expected line.',
];
echo $hints['first'] . PHP_EOL;
// Prints:
// Think about the input shape.
For an array-filtering exercise, an early hint can say “decide which records should remain.” A later hint can name array_filter(). Do not paste the callback if writing it is the skill under review.
Practice
Write Progressive Hints
Write three progressively more specific hints for an exercise that asks learners to find active products in an array and print their names.
Show solution
- Inspect the
activevalue before deciding whether a product stays in the result. array_filter()can keep records that satisfy a callback.- Loop over the remaining products and print each
name.
The hints unblock the learner gradually without supplying the full callback and loop.