Student U and Student V

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

From Humanitarian-FOSS Project Development Site

<html>
<?php
/**
* Days of Christmas
*
* This is a simple php script that sings the 12 days of Christmas,
* It uses a single function and an associateive array.
* @author Student U, Student V
* @version 1.0
*/
?>
  <head></head>
  <body>
  <?php
	/**#@+
	* Constants
	*/
	/**
	* $verses holds the verse number and the gift given.
	*/
        $verses = array("first"=>"a partriage in a pear tree",
                        "second"=>"two turtle doves",
                        "third"=>"three french hens",
                        "fourth"=>"four calling birds",
                        "fifth"=>"five gold 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",);
        
	//this function call initiates the "singing" of the song     
	sing($verses);


	/**
	* Function sing, sings a song.
	*
	* The Sing function takes an array and uses a foreach loop to produce the 12 days of Christmas song
	* from an input array.
	*
	* @param array $song array of indexes and verses.
	* @access public
	* @return void
	*/
        function sing($song)
             {
		//loop through the $song array
		// $day holds the string index of each element
		// $given holds the content of each element itself
                foreach($song as $day => $given){
			//Displays each verse of the song
                        echo "On the $day of Christmas my true love gave to me: {$given}.<br>";
                }
             }
  ?>
  </body>
  </html>
Personal tools