Reputation: 19
I am making an array and ran into a problem I don't know how to loop through a two-dimensial array.
This is my array:
$kaarten = array
(
array("test",12.99),
array("test1",129.99),
array("test2",99.99)
);
I hope you can help me.
Upvotes: 1
Views: 72
Reputation: 64526
A nested foreach would do it:
foreach($kaarten as $subArray)
{
foreach($subArray as $subValue)
{
echo $subValue;
}
}
If you don't need to loop the sub array, then you can directly access the values:
foreach($kaarten as $subArray)
{
echo $subArray[0]; // test
echo $subArray[1]; // 12.99
}
More info: foreach
on the Manual.
Upvotes: 5