View Full Version : Can one return more than one variable using the return; structure in PHP?
05-01-2006, 10:55 PM
I want to return two arrays at the end of a function. Is this possible? If so, is this the correct syntax:
return $array1, $array2;
Thanks a lot.
05-01-2006, 11:00 PM
Nevermind, that would make problems in assigning the results. Sorry for posting w/o thinking first. :o
I'm just going to assign the second array to an element of the first.
05-01-2006, 11:04 PM
you could return the whole thing as a string.
return implode(",", $array1)."|".imploode(",",$array1);
then explode it at the other end.
$returnarrays = explode("|",$returnVal);
$array1 = explode("," $returnarrays);
$array2 = explode(",", $returnarrays);
05-01-2006, 11:40 PM
Very good idea. Thanks a lot.:thumbsup:
05-01-2006, 11:52 PM
$array1 = array('some jazz here', 'some more...');
$array2 = array('another bunch of jibb', 'foobar');
return array($array1, $array2);
list($arr1, $arr2) = rets();
Brandoe's way is a lot nicer, someone else coming along to your and seeing a delimited string being returned might get awfully confused.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.