Reply to Re: How to create html list from such array ?

Your name:

Reply:


Posted by Ewoud Dronkert on 09/30/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/

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация