My attempts at exercism.org
1<?php
2
3declare(strict_types=1);
4
5class Proverb
6{
7 public function recite(array $pieces): array
8 {
9 $output = [];
10
11 for ($i = 0; $i < count($pieces); $i++) {
12 if ($i == count($pieces) - 1 || count($pieces) == 1) {
13 $output[] = "And all for the want of a {$pieces[0]}.";
14 } else {
15 $output[] = "For want of a {$pieces[$i]} the {$pieces[$i + 1]} was lost.";
16 }
17 }
18
19 return $output;
20 }
21}