nested array? How to loop through?
Posted: Thu Aug 05, 2004 1:27 am
Hi there, i seem to have a small problem in my code, i try to loop over an array and display the items in a table structure. Before i can start "designing" the table, i should display any data
The array is like this:
$listings = array (
"item1" => array ( "a"=>"tester1",
"b"=>"tester1_b",
"c"=>"#link1",
"d"=>"/img/1.jpg"),
"item2" => array ( "a"=>"tester2",
"b"=>"tester2_b",
"c"=>"#link2",
"d"=>"/img/2.jpg"),
);
And the code i wrote is like this:
echo "<table>";
for ($i=0; $i<count($listings); $i++)
{ echo "<tr><td>";
echo $listings[$i]['a']."<br>".$listings[$i]['b'];
echo "</td><td>";
echo $listings[$i]['c']."<br>".$listings[$i]['d'];
echo "</td></tr>";
}
echo "</table>";
I can't seem to manage to get the array's within the array ($listing). Could someone perhaps explain me what i am doing wrong please?
The thing a want to accomplish is a table with an image an explanation text on the right. I want to build the layout ones and just add an extra array, if nescesary.
Thx in advance for any response,
Kind regards Robbert
The array is like this:
$listings = array (
"item1" => array ( "a"=>"tester1",
"b"=>"tester1_b",
"c"=>"#link1",
"d"=>"/img/1.jpg"),
"item2" => array ( "a"=>"tester2",
"b"=>"tester2_b",
"c"=>"#link2",
"d"=>"/img/2.jpg"),
);
And the code i wrote is like this:
echo "<table>";
for ($i=0; $i<count($listings); $i++)
{ echo "<tr><td>";
echo $listings[$i]['a']."<br>".$listings[$i]['b'];
echo "</td><td>";
echo $listings[$i]['c']."<br>".$listings[$i]['d'];
echo "</td></tr>";
}
echo "</table>";
I can't seem to manage to get the array's within the array ($listing). Could someone perhaps explain me what i am doing wrong please?
The thing a want to accomplish is a table with an image an explanation text on the right. I want to build the layout ones and just add an extra array, if nescesary.
Thx in advance for any response,
Kind regards Robbert