Re: Help with " Function " parameter

From: Date: Fri, 05 Apr 2002 00:38:11 +0000
Subject: Re: Help with " Function " parameter
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-91647@lists.php.net to get a copy of this message
In article <20020404151532.608.qmail@pb1.pair.com>, fong@btinternet.com (Simonk) wrote: > I have programed a function for counting Date: > > function Datereturn() > { <snip> > Return $realday; > Return $month; > Return $year; > } > > But when I want to echo out the result, I have typed: > > Datereturn(); > echo "$year, $month, $realday"; > > Then the server return: > Undefined variable year, month, realday Re-read the docs on the "return" statement <http://www.php.net/manual/en/function.return.php>. A few pointers: A) As soon as a 'return' is encountered, function execution ends; it will never get to the lines containing additional returns. B) To return multiple values in a single 'return' statement, return an array variable. C) 'Return' does not set variables in the global scope for you; it's up to you to explicity set a variable. function myFunc() { ... return array ($one, $two, $three); } $returned=myFunc(); echo "{$returned[0]}, {$returned[1]}, {$returned[2]}"; -- CC

« previous php.general (#91647) next »