$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.
How Do You Use Php To Display A Two Columns Per Row Html Table?
December 28th, 2009 by CTO WebOjO.com website designers Lahore Pakistan Leave a reply »
Advertisement
< ?php
$arr = array("apple","orange","banana","grape",…
$n = count($arr);
$q = ceil($n /2);
echo '
$arrN = 0;
for($i=$q;$i< =$n;$i++) {
echo "
$arrN++;
echo “$arr[$arrN]
“;
$arrN++;
}
echo ““;
?>
A bit basic, is it not?
< ?php
$arr = array ("apple", "orange", "banana", "grape", "pineapple");
$txt = "
$siz = sizeof ($arr);
$col = 0;
for ($i=0; $i< $siz; $i++)
{
if ($col == 0)
$txt .= "
$txt .= “
“;
$col++;
if ($col == 2)
{
$col = 0;
$txt .= ““;
}
}
if ($col != 0)
$txt .= ““;
$txt .= ““;
echo ($txt);
?>
$a = $arr;
if (count($a) % 2 != 0) $a[] = ”; // Pad to an even # of elements
echo ‘
for ($i=0; $i
‘;
echo ‘
‘;
WebOjO
G-73 2nd Floor Phase I DefenceLahore, Pakistan +92-42-35734780 +92-42-35893185 +92-333-4599404 +92-333-4687466
Powered by Yahoo Answers
Back to Top
© 2010 Pakistan Website Design Services by WebOjO.com · Proudly powered by WordPress & Green Park 2 by Cordobo.
Valid XHTML 1.0 Transitional | Valid CSS 3