|
Posted by Ewoud Dronkert on 11/10/26 11:17
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/
Navigation:
[Reply to this message]
|