Array Loop

I have this statement, I cannot figure out how to make it a loop:
[php] if (empty($listeners[3][‘hostname’])){
echo “”;
} else {
echo “”;
echo $listeners[3][‘hostname’];
echo "

";
echo $listeners[3][‘useragent’];
echo "
";
echo $ctry_name3;
echo "
";
echo gmdate(“H:i:s”, $listeners[3][‘connecttime’]);
echo " "; } [/php]

I want it to run for as many parts of the array as there are. so if there are 40 listeners in the array, I want it to show all 40.

I’d assume I could do a while loop, but I cannot figure out how.

Hi there,

Try this:
[php]foreach($listeners as $listener)
{
echo “”;
echo $listener[‘hostname’];
echo "

";
echo $listener[‘useragent’];
echo "
";
echo $ctry_name3;
echo "
";
echo gmdate(“H:i:s”, $listener[‘connecttime’]);
echo "
}
[/php]

I haven’t tested this though, so let me know how it goes.

Sponsor our Newsletter | Privacy Policy | Terms of Service