Student E, Student F, and Student G

12 Days of PHP
The 12 Days of Christmas

"A Partridge in a Pear Tree",   	"second"=>"Two Turtle Doves",   	"third"=>"Three French Hens",   	"fourth"=>"Four Calling Birds",   	"fifth"=>"Five Golden Rings",   	"sixth"=>"Six Geese A-laying",   	"seventh"=>"Seven Swans A-swimming",   	"eigth"=>"Eight Maids A-milking",   	"ninth"=>"Nine Ladies Dancing",   	"tenth"=>"Ten Lords A-leaping",   	"eleventh"=>"Eleven Pipers Piping",   	"twelfth"=>"Twelve Drummers Drumming");

print " "; sing($days); print " ";

/** * Function that will print out the lyrics of Twelve Days of Christmas. * It will sing the song in the format given on http://www.carols.org.uk/the_twelve_days_of_christmas.htm * * @param array $lyric */ function sing($lyric) {  	$i=0; foreach ($lyric as $number=>$gift){ print "On the {$number} day of Christmas, "; print "my true love sent to me "; print $gift; sing_partly(array_reverse(array_slice($lyric,0,$i))); print " "; $i++; } }

/** * Helper function of sing. It will print out the song in an array with a comma in * between and the last element will be "AND ... ." * * @param array $array */

function sing_partly($array){ $size = sizeof($array); $i=0; if($size != 0){ foreach($array as $number=>$gift){ print ", "; if($i != ($size-1)){ print $gift; }else{ print "And ".$gift."."; }			$i++; }	} } ?>

This code is implemented in |Bach's module in WeSahana.