Student X

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

From Humanitarian-FOSS Project Development Site

<html>
<?php>
/* Twelve Days
*
*Program writes the song "The Twelve Days of Christmas"
*
*Student X
*
*/
?>




<head>
<title>The Twelve Days of Christmas</title>
<?php>


$day=array("first"=>"A partridge in a pear tree",	//array that holds the verse information
              "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",
              "eighth"=>"Eight maids a-milking",
              "ninth"=>"Nine ladies dancing",
              "tenth"=>"Ten lords a-leaping",
              "eleventh"=>"Eleven pipers piping",
              "twelfth"=>"Twelve drummers drumming");



function sing_days($verses)	//uses a foreach loop to print the day and verses
{
	$i=0;
	$temp = array("","","","","","","","","","","","");
	foreach($verses as $daynum=>$gift){
		print("On the $daynum day of christmas<BR>");
		print("My true love gave to me<BR>");
		print("$gift<BR>");
		$temp[$i] = $gift;		// adds already used verses to a new array
		for ($x = $i-1;$x>=0;$x--){		//prints the verses before the current day
			if ($x==0){
				print("And " . strtolower($temp[$x]) . "<BR>");		
			}
			else{
				print("$temp[$x]<BR>");
			}
		}
		$i++;
		print("<BR>");
		
	}
}

?>
</head>

<body>
<?php>
	sing_days($day);	//calls the function that writes the song
?>
</body>
</html>
Personal tools