Student K and Student L

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

From Humanitarian-FOSS Project Development Site

For the result, click here
For the documentation, click here


<html>
<title>The Twelve Days of Christmas</title>
<center>
<h1>The Twelve Days of Christmas</h1><br>

<?php

   /**
    *  twelvedays.php - a PHP program that sings the "Twelve Days of Christmas"
    *
    *  This code prints out each day of Christmas along with its
    * corresponding gifts in "The Twelve Days of Christmas".
    *
    *  @author  Student K, Student L
    *  @version 1.0
    */

   /**
    *  Define an associative array to store the days (keys) along with their
    * corresponding gifts (values)
    */

    $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",
                  "eighth" => "eight maids a-milking",
                  "ninth" => "nine ladies dancing",
                  "tenth" => "ten lords a-leaping",
                  "eleventh" => "eleven pipers piping",
                  "twelfth" => "twelve drummers drumming");

   /**
    *  Define an array that will map integers to each day
    */

    $num = array(1 => "first","second","third","fourth","fifth","sixth",
                      "seventh","eighth","ninth","tenth","eleventh","twelfth");

   /**
    *  Prints a verse from "The Twelve Days of Christmas"
    *
    *  This function prints a verse from the song "The Twelve Days of Christmas"
    *
    *  @param integer $day the day
    *  @return void
    */

    function print_day($day)
    {
        global $num;
        global $days;
    
        $verse = "On the " . $num[$day] . " day of Christmas, my true love gave to me<br>\r\n";

        for($i = $day; $i > 0; $i--)
        {
            if(($i == 1) && ($day == 1))
            {
                $verse .= $days[$num[$i]] . ".<br>\r\n";
            }
            else if($i == 1)
            {
                $verse .= "and " . $days[$num[$i]] . ".<br>\r\n";
            }
            else
            {
                $verse .= $days[$num[$i]] . ",<br>\r\n";
            }
        }

        print($verse);
    }

   /**
    * Iterate through the array and print each day with its gift
    */

    foreach($num as $int_day => $string_day)
    {
        print_day($int_day);
        print("<br>\r\n\r\n");
    }

?>

</center>
</html>


Personal tools