I have a nested array in which I want to display a subset of results. For example, on the array below I want to loop through all the values in nested array[1].
Array ( [0] => Array ( [0] => one [1] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) [1] => Array ( [0] => two [1] => Array ( [0] => 4 [1] => 5 [2] => 6 ) ) [2] => Array ( [0] => three [1] => Array ( [0] => 7 [1] => 8 [2] => 9 ) ) )
I was trying to use the foreach function but I cannot seem to get this to work. This was my original syntax (though I realise it is wrong).
$tmpArray = array(array("one",array(1,2,3)),array("two",array(4,5,6)),array("three",array(7,8,9))); foreach ($tmpArray[1] as $value) { echo $value; }
I was trying to avoid a variable compare on whether the key is the same as the key I want to search, i.e.
foreach ($tmpArray as $key => $value) { if ($key == 1) { echo $value; } }
Any ideas?