Re: General Function usage question (simple)

From: Date: Sat, 14 Feb 2004 08:03:20 +0000
Subject: Re: General Function usage question (simple)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-177693@lists.php.net to get a copy of this message
On Sat, 2004-02-14 at 02:31, Dave Carrera wrote: > My question is what do or where do or why are the $var1 and or $var2 > included inside the brackets of a function. > > What do they do ? > > Why are they in there ? > > And how are they used within an application ? A good place to start reading about functions is in the php manual[1]. In short, functions are blocks of code that achieve a particular purpose, or function. Arguments[2] are used with functions to pass information, or variables, to these blocks of code. Generally the arguments are used or manipulated by the function. Functions may pass back, or return[3], information as well. Here are some sample functions, function calls, and output for context. Steps are separated as much as possible for clarity: // No arguments function echoHelloWorld() { echo "Hello World\n"; } echoHelloWorld(); // Output: Hello World // Has arguments, uses data. function printPlusOne($number) { $number = $number + 1; echo $number . "\n"; } printPlusOne(2); // Output: 3 // Has arguments, manipulates and returns data. function doubleNumber($number) { $number = $number * 2; return $number; } $value = doubleNumber(10); echo $value . "\n"; // Output: 20 Good Luck, Adam [1] http://www.php.net/functions [2] http://www.php.net/functions.arguments [3] http://us2.php.net/functions.returning-values -- Adam Bregenzer adam@bregenzer.net http://adam.bregenzer.net/

« previous php.general (#177693) next »