Student E, Student F, and Student G

[article] [edit page] [discussion] [history]

From Humanitarian-FOSS Project Development Site

12 Days of PHP

<title>The 12 Days of Christmas</title>


* This file contains the code to print out the 12 Days of Christmas song, utilizing an associative array.
 * @author Student F
 * @version 1.0
 * @package default

$days = array(
   	"first"=>"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 "<center>";	
print "</center>";

 * Function that will print out the lyrics of Twelve Days of Christmas.
 * It will sing the song in the format given on
 * @param array $lyric
function sing($lyric)
	foreach ($lyric as $number=>$gift){
		print "On the {$number} day of Christmas,<br>";
		print "my true love sent to me <br>";
		print $gift;
		print "<br><br>";

 * 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);
	if($size != 0){
		foreach($array as $number=>$gift){
			print ",<br>";
			if($i != ($size-1)){
				print $gift;
				print "And ".$gift.".";

This code is implemented in module in WeSahana.

Personal tools