Topic: function parameters

Hi,
In the code below, I understand the $place variable and how it's working. What I can't understand is how I'M getting the output "he played 1, 2, etc... How is that function and the $stanza variable returning a single digit number? Thanks
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Param Old Man</title>
</head>

<body>

<h1>Param Old Man</h1>
<h3>Demonstrates use of function parameters</h3>
<?php

print verse(1);
print chorus();
print verse(2);
print chorus();
print verse(3);
print chorus();
print verse(4);
print chorus();

function verse($stanza)
{
    switch($stanza)
    {
        case 1:
            $place = "thumb";
            break;
        case 2:
            $place = "shoe";
            break;
        case 3:
            $place = "knee";
            break;
        case 4:
            $place = "door";
            break;
        default:
            $place = "I don't know where";
    } //end switch

    $output = <<<HERE
    This old man, he played $stanza<br>
    He played knick-knack on my $place<br><br>
HERE;
    return $output;
} //end veruse

function chorus()
{
    $output = <<<HERE
    ...with a knick-knack<br>
    paddy-wack<br>
    give a dog a bone<br>
    this old man came rolling home<br>
    <br><br>
HERE;
    return $output;
}// end chorus

?>
</body>
</html>

Re: function parameters

I don't really understand your question smile

print verse(2); call verse(2), which returns

This old man, he played 2<br>
He played knick-knack on my shoe<br><br>

After this string has been returned to function print, this function will ouput that string to your stdout: command line or web browser.

With SetCronJob.com you can create unlimited free cron jobs every 5 minutes :)

Re: function parameters

Your question is: why you're getting a number after "This old man, he played"?

Well, because you have "This old man, he played $stanza" on your string and $stanza is the number you give the function.