Last active 2 months ago

josh revised this gist 2 months ago. Go to revision

1 file changed, 1 insertion, 1 deletion

12days.php

@@ -36,7 +36,7 @@ foreach($map as $x => $day){
36 36 case 'eighth':
37 37 $verse .= "eight maids a-milking,";
38 38 case 'seventh':
39 - $verse .= "seven swans a-swimming,";
39 + $verse .= "seven swans a-swimming,";
40 40 case 'sixth':
41 41 $verse .= "six geese a-laying,";
42 42 case 'fifth':

josh revised this gist 2 months ago. Go to revision

1 file changed, 58 insertions

12days.php(file created)

@@ -0,0 +1,58 @@
1 + <?php
2 + declare(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 +
19 + function extend(string $vowel, int $iteration): string {
20 + return str_repeat($vowel, rand(1, $iteration));
21 + }
22 +
23 + foreach($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 + }
Newer Older