How do you use php to display a two columns per row html table?

Peter

New member
$arr=array("apple","orange",
"banana","grape",
"pineapple");


I want to display the array in a html table using php (foreach loop preferred), two columns per row like this:

apple orange
banana grape
pineapple

Many thanks to you all.
All solutions are very good, I need to put it to vote
 
<?php
$arr = array("apple","orange","banana","grape","pineapple");
$n = count($arr);
$q = ceil($n /2);
echo '<table>';
$arrN = 0;
for($i=$q;$i<=$n;$i++) {
echo "<tr><td>$arr[$arrN]</td><td>";
$arrN++;
echo "$arr[$arrN]</td></tr>";
$arrN++;
}
echo "</table>";
?>
 
Back
Top