php - Nested array to 3-level unordered list -
i have nested array, , looking turn unordered list:
[2009] => array ( [show name 1] => array ( [0] => class 1 [1] => class 2 ) ) [2008] => array ( [show name 2] => array ( [0] => class 1 [1] => class 2 ) )
and turn into:
2009 show name 1 class 1 class 2 2008 show name 2 class 1 class 2
so far have partially managed it, being able show year, after 'array' show name should be:
2012 array array 2009 array 2008 array
i made using following:
<ul> <?php foreach( $results $year => $shows ): ?> <li><?= $year ?> <ul> <?php foreach( $shows $show ): ?> <li><?= $show ?></li> <?php endforeach; ?> </ul> </li> <?php endforeach; ?> </ul>
update
i need grab year_id, show_id, class_id each result, can pass them url. like:
<ul class="no-bullet"> <?php foreach( $results $year => $shows ): ?> <li><h2><?= $year ?></h2> <ul class="no-bullet"> <?php foreach( $shows $show_name => $show ): ?> <li><h4><?= $show_name ?></h4></li> <ul class="no-bullet"> <?php foreach( $show $class ): ?> <li><a href="results.html?year=$yearid&show=$showid&class=$classid"><?= $class ?></a></li> <?php endforeach; ?> </ul> <?php endforeach; ?> </ul> </li> <?php endforeach; ?> </ul>
however, haven't foggiest start. considered query within foreach loop, figured may quite inefficient?
you need treat $show
array , extract part want, this:
<ul> <?php foreach( $results $year => $shows ): ?> <li><?= $year ?> <ul> <?php foreach( $shows $show_name => $show ): ?> <li><?= $show_name ?> <ul> <?php foreach( $show $class ): ?> <li><?= $class ?></li> <?php endforeach; ?> </ul> </li> <?php endforeach; ?> </ul> </li> <?php endforeach; ?> </ul>
Comments
Post a Comment