RE: [PHP] Speaking of Global Annoyance
| From: | Jonathan Sharp | Date: | Tue, 19 Dec 2000 02:50:46 +0000 |
| Subject: | RE: [PHP] Speaking of Global Annoyance | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-30978@lists.php.net to get a copy of this message | ||
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...
-Jonathan
-----Original Message-----
From: php3@developersdesk.com [mailto:php3@developersdesk.com]
Sent: Monday, December 18, 2000 6:44 PM
To: Jonathan Sharp; php-general@lists.php.net
Subject: RE: [PHP] Speaking of Global Annoyance
Addressed to: "Jonathan Sharp" <webdev@flyerware.com>
<php-general@lists.php.net>
** Reply to note from "Jonathan Sharp" <webdev@flyerware.com> Mon, 18 Dec
2000 15:51:19 -0800
>
> but it's kinda hard to
> return arrays since you can't just do "return $thearray;" and then on
> the other end "$anarray = somefunction();"
Yes you can.
------------------------------------------------
<?
function ReturnArray() {
$Array = array( 1, 2, 3 );
return $Array;
}
$AnotherArray = ReturnArray();
list( $One, $Two, $Three ) = $AnotherArray;
echo "One: $One Two: $Two Three: $Three<BR>\n";
?>
------------------------------------------------
Returns:
One: 1 Two: 2 Three: 3
function ReturnArray() {
return array( 1, 2, 3 );
}
would do the same thing.
function ReturnComplex() {
return array( array( 'Entry[1][1]',
'Entry[1][2]',
'Entry[1][3]' ),
array( 'Entry[2][1]',
'Entry[2][2]',
'Entry[2][3]' ),
array( 'Entry[3][1]',
'Entry[3][2]',
'Entry[3][3]' ));
}
will work too.
$ReturnValue = ReturnComplex();
echo $ReturnValue[2][3]; // Entry[2][3]
Rick Widmer
Internet Marketing Specialists
http://www.developersdesk.com