Challenge 3 — Solution Task: Create a SortStrategy interface with a sort(array $items): array method, and two implementations: AscendingSort and DescendingSort. Write a class Report that accepts a SortStrategy via its constructor and a generate(array $items) method using it. Demonstrate swapping strategies on two different Report instances with the same data. strategy->sort($items); } } $data = [42, 7, 19, 3, 88]; $ascendingReport = new Report(new AscendingSort()); $descendingReport = new Report(new DescendingSort()); print_r($ascendingReport->generate($data)); print_r($descendingReport->generate($data)); ?> Output: Array ( [0] => 3 [1] => 7 [2] => 19 [3] => 42 [4] => 88 ) Array ( [0] => 88 [1] => 42 [2] => 19 [3] => 7 [4] => 3 ) Notes: - Both Report instances are constructed with the identical $data array, yet produce completely different results purely because of which SortStrategy object was injected via the constructor - Report itself never changes, and never contains any sorting logic of its own. - This is exactly the ShoppingCart/DiscountStrategy pattern from the chapter, applied to a different problem: swapping behaviour means passing a different object in, not modifying the class that uses it. - sort() and rsort() are PHP's own built-in array-sorting functions (from Intermediate Chapter 6), reused here as the concrete implementation behind each strategy's own interface method.