Last active 2 months ago

Revision 7a161335fa8d986bb90fdb7c47bcfec00b2cb1ec

12days.php Raw
1<?php
2declare(strict_types=1);
3
4$map = [
5 'first',
6 'second',
7 'third',
8 'fourth',
9 'fifth',
10 'sixth',
11 'seventh',
12 'eighth',
13 'ninth',
14 'tenth',
15 'eleventh',
16 'twelfth',
17];
18
19function extend(string $vowel, int $iteration): string {
20 return str_repeat($vowel, rand(1, $iteration));
21}
22
23foreach($map as $x => $day){
24 $verse = "";
25 $verse .= "on the {$day} day of Christmas my true love sent to me,";
26
27 switch($day){
28 case 'twelfth':
29 $verse .= "twelve drummers drumming,";
30 case 'eleventh':
31 $verse .= "eleven pipers piping,";
32 case 'tenth':
33 $verse .= "ten lords a-leaping,";
34 case 'ninth':
35 $verse .= "nine ladies dancing,";
36 case 'eighth':
37 $verse .= "eight maids a-milking,";
38 case 'seventh':
39 $verse .= "seven swans a-swimming,";
40 case 'sixth':
41 $verse .= "six geese a-laying,";
42 case 'fifth':
43 $verse .= "F" . extend("I", $x) . "VE G" . extend("O", $x) . "LDEN R" . extend("I", $x) . "NGS,";
44 case 'fourth':
45 $verse .= "four calling birds,";
46 case 'third':
47 $verse .= "three french hens,";
48 case 'second':
49 $verse .= "two turtle doves,";
50 $verse .= "and ";
51 default:
52 $verse .= "a partridge in a pear tree,";
53 }
54 $verse = explode(",", $verse);
55 array_walk($verse, function(string $val, $index){
56 echo ucfirst($val), PHP_EOL;
57 });
58}
59