How can I pass an array to a function?
Let’s say I have this multi-dimensional array:
$TheArray = (
array("Value 1 0","Value 1 1","Value 1 2"),
array("Value 2 0","Value 2 1","Value 2 2"),
array("Value 3 0","Value 3 1","Value 3 2")
);
Instead of doing this…
for ($i=0; $i<=(count($TheArray)-1); $i++)
{
echo $TheArray[$i][0] . " " . $TheArray[$i][1] . " " . $TheArray[$i][2] . "<br />";
}
I want to do this…
function DoStuffWithTheArray($SubArr)
{
echo $SubArr[0] . " " . $SubArr[1] . " " . $SubArr[2] . "<br />";
}
for ($i=0; $i<=(count($TheArray)-1); $i++)
{
DoStuffWithTheArray($TheArray[$i]);
}
Hopefully, you can tell what I am trying to do, but I do not know how to get it to work. When I do try it the way I want, all the values are empty
I think, you need to learn first how create an array;
Second, change this style please and see: http://php.net/manual/en/control-structures.foreach.php
And answer;