Passing an array out of a function

software development


Hi. I’m trying to pass 2 variables out of a function and read in the php manual that the only way to do it was to assign the values to an array.

I’ve tried everything I can think of to get the values into the array, but I just keep getting a length of zero. No error messages, just no values.

function myfunction()
$var1 = somevalue;
$var2 = another value;

$arr[‘v1’]= $var1;
$arr[‘v2’]= $var2;

return $arr;

$len = sizeof($arr);

I keep getting a length of zero and trying to access the array by the index doesn’t return any values. I also tried various other methods.

Any help would be appreciated. :slight_smile:


The problem is in how you call the function… you need to store the return value in a variable, like so:

$arr = myfunction();