I have a multidimensional array called $arr_results as follows:I want to loop through each element in the array, and for each one print out it's values for T, D, U, Y, C, I.Code:Array ( [0] => Array ( [T] => Title 0 [D] => Description 0 [U] => Real URL 0 [Y] => Fake URL 0 [C] => Cost 0 [I] => Image URL 0 ) [1] => Array ( [T] => Title 1 [D] => Description 1 [U] => Real URL 1 [Y] => Fake URL 1 [C] => Cost 1 [I] => Image URL 1 ) [2] => Array ( [T] => Title 1 [D] => Description 1 [U] => Real URL 1 [Y] => Fake URL 1 [C] => Cost 1 [I] => Image URL 1 ) )
I'm using the following code to do it:This code works fine if the main array index starts at 0 and increments by 1.PHP Code:if(count($arr_results) > 1)
{
for($counter=0; $counter<count($arr_results); $counter++)
{
print($counter + 1);
print($arr_results[$counter]["T"]);
print($arr_results[$counter]["D"]);
print($arr_results[$counter]["U"]);
print($arr_results[$counter]["Y"]);
print($arr_results[$counter]["C"]);
print($arr_results[$counter]["I"]);
}
}
My problem is that often it starts at some other number and then the whole thing falls appart.
Say for example my array looked like this, how would I do it?Code:Array ( [6] => Array ( [T] => Title 6 [D] => Description 6 [U] => Real URL 6 [Y] => Fake URL 6 [C] => Cost 6 [I] => Image URL 6 ) [8] => Array ( [T] => Title 8 [D] => Description 8 [U] => Real URL 8 [Y] => Fake URL 8 [C] => Cost 8 [I] => Image URL 8 ) [13] => Array ( [T] => Title 8 [D] => Description 8 [U] => Real URL 8 [Y] => Fake URL 8 [C] => Cost 8 [I] => Image URL 8 ) )




Reply With Quote