I have a function and I need it to return two arrays.
I know a function can only return one variable .. is there a way to return my two arrays?
If I concatenate them, how can I separate them cleanly when out of the function?
I have a function and I need it to return two arrays. I know a function can only return one variable .. is there a way to return my two arrays? If I concatenate them, how can I separate them cleanly when out of the function? |
||||
|
No need to concatenate: just return array of two arrays, like this:
... then you will be able to assign these arrays to the local variables with list, like this:
And if you work with PHP 5.4, you can use array shortcut syntax here as well:
|
|||||||||||||
|
I think raina77ow's answer adequately answers your question. Another option to consider is to use write parameters.
Then, to call:
This won't be useful if you always need to return two arrays, but it can be used to always return one array and return the other only in certain cases. |
|||
|