RE: [PHP] Speaking of Global Annoyance

From: Date: Tue, 19 Dec 2000 22:42:18 +0000
Subject: RE: [PHP] Speaking of Global Annoyance
Groups: php.general 
Request: Send a blank email to php-general+get-31060@lists.php.net to get a copy of this message
I was wrong, what I was looking at was http://www.php.net/manual/functions.returning-values.php as it says "You can't return multiple values from a function, but similar results can be obtained by returning a list. function small_numbers() { return array (0, 1, 2); } list ($zero, $one, $two) = small_numbers();" So I stand corrected, you can return an array with a function. -Jonathan -----Original Message----- From: php3@developersdesk.com [mailto:php3@developersdesk.com] Sent: Monday, December 18, 2000 9:14 PM To: Jonathan Sharp; phpgeneral@lists.php.net Subject: RE: [PHP] Speaking of Global Annoyance Addressed to: "Jonathan Sharp" <webdev@flyerware.com> phpgeneral@lists.php.net ** Reply to note from "Jonathan Sharp" <webdev@flyerware.com> Mon, 18 Dec 2000 18:50:46 -0800 > > Well...you're correct, you can return them as long as you have a > fixed number of elements...but if you have a function that returns an > array with n elements...it's quite hard to use the list() > function...it's not quite as easy as what I said before... > > function ReturnArray(){ $Array = array(n, n1, nn); return $Array; } > > $Array = ReturnArray(); > > That won't work...so if you're not returning a fixed number of > elements, it's a pain in the dajubuiti... Print the contents of an array where you don't know how many elements there are: $Array = ReturnArray(); $Count = 0; while( list( $Key, $Value ) = each( $Array )) { $Count ++; echo "Count $Count Key: $Key Value: $Value<BR>\n" ; } echo "There are $Count elements in the unknown array.<BR>\n"; Its not so hard... Rick Widmer Internet Marketing Specialists http://www.developersdesk.com

« previous php.general (#31060) next »