RE: [PHP] question
| From: | Don Read | Date: | Sun, 30 Mar 2003 12:54:52 +0000 |
| Subject: | RE: [PHP] question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-141636@lists.php.net to get a copy of this message | ||
On 30-Mar-2003 Marius wrote:
> <?php
> $i = 0;
> $list = array('Banana', 'Strawberry', 'Apple',
> 'Cherry');
> echo $list[$i];
> $i = $i+1;
> ?>
>
> how to do that 2 of key echoes in first table colum and other 2 in
> second colum?
>
Method 1:
$i=0;
echo '<tr><td>
foreach($list as $v) {
echo $v, '<br>';
if (! (++$i % 2))
echo '</td>';
if ($i < count($list))
echo '<td>';
}
}
echo '</tr>';
Method 2:
echo '<tr>';
unset($blk);
foreach($list as $v) {
if (count($blk) >= 2) {
echo '<td>', implode('<br>', $blk), '</td>';
unset($blk);
}
$blk[] = $v;
}
if (count($blk) )
echo '<td>', implode('<br>', $blk), '</td>';
echo '</tr>';
Regards,
--
Don Read dread@texas.net
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.