Re: Help with functions.

From: Date: Fri, 01 Mar 2002 02:33:29 +0000
Subject: Re: Help with functions.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-86709@lists.php.net to get a copy of this message
> I need some help with functions. Does anyone know of a good place to learn > about functions? Will someone be willing to teach me what I need to know about > functions in PHP? Thank you, Here's a really simple example: <? // regular variable that exists outside any functions $global_var = 5; // we will pass this variable to the function $passed_var = 7; // define the function function function_name ($passed_var){ // pull in any needed global variables not local or passed to the function global $global_var; // regular variable that exists only in this function $local_var = 10; // build up the html $html = "Now inside function_name()...<br>\n"; // build up some more html $html .= "\$global_var + \$local_var + \$passed_var = " . $global_var + $local_var + $passed_var . "<br>\n"; // pass the $html back to the caller return $html; } // call the function echo function_name ($passed_var); ?> Usually you wanna use funtions for code you intend to use multiple times. ------------------------------------------------------------------------ Greg Donald - http://destiney.com/ http://phprated.com/ | http://phplinks.org/ | http://phptopsites.com/ ------------------------------------------------------------------------

« previous php.general (#86709) next »