Re: How to create html list from such array ?
- From: Ewoud Dronkert <firstname@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 30 May 2005 16:15:26 +0200
On Mon, 30 May 2005 13:29:31 +0200, lp wrote:
> $myArr = array(
> array("jj", "0", "jjj"),
> array("ee", "0", "eee"),
> array("bb", "ee", "bbb"),
> array("ll", "ee", "lll"),
> array("ff", "0", "fff"),
> )
>
> <ul>
> <li>jjj</li>
> <li>eee
> <ul>
> <li>bbb</li>
> <li>eee</li>
> </ul>
> </li>
> <li>fff</li>
> <ul>
How about
$html = "<ul>\n";
$prv = -1;
foreach ( $myArr as $a )
{
$cur = $a[1];
$dat = "\t<li>{$a[2]}";
if ( $prv !== -1 )
if ( strcmp( $cur, '0' ) == 0 )
{
$dat = "</li>\n$dat";
if ( strcmp( $prv, '0' ) != 0 )
$dat = "\t\t</ul>\n\t$dat";
}
else
{
$dat = "\t\t$dat</li>\n";
if ( strcmp( $prv, '0' ) == 0 )
$dat = "\n\t\t<ul>\n$dat";
}
$html .= $dat;
$prv = $cur;
}
if ( strcmp( $prv, '0' ) != 0 )
$html .= "\t\t</ul>\n\t";
$html .= "</li>\n</ul>\n";
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
.
- References:
- Prev by Date: Re: How to create html list from such array ?
- Next by Date: Re: templates?
- Previous by thread: Re: How to create html list from such array ?
- Next by thread: templates?
- Index(es):