The data function is returning an array, so you can access the result of the function in the same way as you would normally access elements of an array:
I think the best way to do it is to create a global var array. Then do whatever you want to it inside the function data by passing it as a reference. No need to return anything too.
$array = array("white", "black", "yellow");
echo $array[0]; //this echo white
data($array);
function data(&$passArray){ //<<notice &
$passArray[0] = "orange";
}
echo $array[0]; //this now echo orange
In order to get the values of each variable, you need to treat the function as you would an array:
function data() {
$a = "abc";
$b = "def";
$c = "ghi";
return array($a, $b, $c);
}
// Assign a variable to the array;
// I selected $dataArray (could be any name).
$dataArray = data();
list($a, $b, $c) = $dataArray;
echo $a . " ". $b . " " . $c;
//if you just need 1 variable out of 3;
list(, $b, ) = $dataArray;
echo $b;
//Important not to forget the commas in the list(, $b,).
I was looking for an easier method than i'm using but it isn't answered in this post. However, my method works and i don't use any of the aforementioned methods:
I have no problems with my function. I read the data in a loop to display my associated data. I have no idea why anyone would suggest the above methods. If you are looking to store multiple arrays in one file but not have all of them loaded, then use my function method above. Otherwise, all of the arrays will load on the page, thus, slowing down your site. I came up with this code to store all of my arrays in one file and use individual arrays when needed.