There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Software Development
Tag Cloud
adware audio bios blue screen boot bsod card computer crash dell desktop driver drivers error excel firefox freeze freezing google hard drive hardware hijackthis install internet laptop linux malware network no sound outlook problem router screen server slow sound speakers spyware startup trojan usb video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
function parameters

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
gilbertsavier's Avatar
Junior Member with 9 posts.
 
Join Date: Jun 2009
29-Jun-2009, 02:02 AM #1
function parameters
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>
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 5,315 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
29-Jun-2009, 03:08 AM #2
Welcome to TSG!

print verse(1)
This calls the function verse, passing it the number (1 in this case, next call passes 2, and so on)

function verse($stanza)
The function declaration says take the passed value and assign it to $stanza

Jerry
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 04:12 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.