12days.php
· 1.3 KiB · PHP
Raw
<?php
declare(strict_types=1);
$map = [
'first',
'second',
'third',
'fourth',
'fifth',
'sixth',
'seventh',
'eighth',
'ninth',
'tenth',
'eleventh',
'twelfth',
];
function extend(string $vowel, int $iteration): string {
return str_repeat($vowel, rand(1, $iteration));
}
foreach($map as $x => $day){
$verse = "";
$verse .= "on the {$day} day of Christmas my true love sent to me,";
switch($day){
case 'twelfth':
$verse .= "twelve drummers drumming,";
case 'eleventh':
$verse .= "eleven pipers piping,";
case 'tenth':
$verse .= "ten lords a-leaping,";
case 'ninth':
$verse .= "nine ladies dancing,";
case 'eighth':
$verse .= "eight maids a-milking,";
case 'seventh':
$verse .= "seven swans a-swimming,";
case 'sixth':
$verse .= "six geese a-laying,";
case 'fifth':
$verse .= "F" . extend("I", $x) . "VE G" . extend("O", $x) . "LDEN R" . extend("I", $x) . "NGS,";
case 'fourth':
$verse .= "four calling birds,";
case 'third':
$verse .= "three french hens,";
case 'second':
$verse .= "two turtle doves,";
$verse .= "and ";
default:
$verse .= "a partridge in a pear tree,";
}
$verse = explode(",", $verse);
array_walk($verse, function(string $val, $index){
echo ucfirst($val), PHP_EOL;
});
}
| 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 | } |
| 59 |