Page 1 of 1

Returning an Array from a Function

Posted: Thu May 27, 2004 4:03 pm
by webcan
Would someone be kind enough to post a simple/minimal example of how a function, my_function, would return an array of two strings, say "abc" and "def" (versus returning a single value).

I've looked in O'reilly's PHP book on page 339 (for those that have it) but I can't get it to work, I suspect because the example isn't a real example.

Thanks,
Peter.

Posted: Thu May 27, 2004 4:03 pm
by feyd
return array('abc','def');

Posted: Thu May 27, 2004 5:49 pm
by webcan
Wow, that is totally easy. :) So unlike the example in the book.

Ok, one last question, let's say I already have an array $data that I populate elsewhere in the function, how do I return it? return($data)?

Thanks,
Peter.

Posted: Thu May 27, 2004 5:55 pm
by tim
FYI - you only need the parentheses if the data contains an expression, which an array does not.


return $data;

Posted: Thu May 27, 2004 5:57 pm
by webcan
OK, thanks.