我想要genreate父親 - 孩子和他們的孩子等 我有一個數組,其子項意味着子項目。在PHP中的父母孩子和他們的孩子的關係
$navarray= Array
(
[0] => Array
(
[id] => 3
[name] => add
[controller] => ClassYearsSubjectsController
[action] => getsubjects
[parent] => 0
[sub] => Array
(
)
)
[1] => Array
(
[id] => 1
[name] => occupations
[controller] => OccupationsController
[action] => index
[parent] => 0
[sub] => Array
(
[0] => Array
(
[id] => 7
[name] => test
[controller] => AddressesController
[action] => index
[parent] => 1
[sub] => Array
(
[0] => Array
(
[id] => 8
[name] => testnew
[controller] => AdmissionEnquiriesController
[action] => giveadmissions
[parent] => 7
[sub] => Array
(
)
)
)
)
[1] => Array
(
[id] => 2
[name] => add
[controller] => OccupationsController
[action] => add
[parent] => 1
[sub] => Array
(
)
)
)
)
)
我想ot生成樹。 但我想
<?php echo GenerateNavHTML($navarray); ?>
和功能GenerateNavHTML
<?php
function GenerateNavHTML($nav)
{
$html = '';
foreach($nav as $page)
{
$html.='<ul><li>';
$html .= '<a href="#">k</a>';
$html .= GenerateNavHTML($page['sub']);
$html .= '</li></ul>';
}
return $html;
}
?>
而且我的輸出是
<ul style="display: block;" class="nav">
<li class="test"><a href="">add</a>
</li>
</ul><ul style="display: block;" class="nav"><li class="test"><a href="">occupations</a><ul style="display: block;" class="nav"><li class="test"><a href="">test</a><ul style="display: block;" class="nav"><li class="test"><a href="">testnew</a></li></ul></li></ul><ul style="display: block;" class="nav"><li class="test"><a href="">add</a></li></ul></li></ul>
,但我期待着這個輸出。
<ul style="display: block;" class="nav">
<li class="test">
<li class="test">
<a class="parent" href="#">Shoes</a>
<ul>
<li>
<a class="parent" href="#">Womens</a>
<ul>
<li><a href="#">Sandals</a></li>
<li><a href="#">Sneakers</a></li>
<li><a href="#">Wedges</a></li>
<li><a href="#">Heels</a></li>
<li><a href="#">Loafers</a></li>
<li><a href="#" class="last" >Flats</a></li>
</ul>
</li>
<li>
<a class="parent last" href="#">Mens</a>
<ul>
<li><a href="#">Loafers</a></li>
<li><a href="#">Sneakers</a></li>
<li><a href="#">Formal</a></li>
</ul>
</li>
</ul>
</li>
</ul>
Can anybody tell what logic i need to change
Thanks
看到的數據存儲位置的wordpress層次類別結構 – 2013-04-11 12:25:24
?在Mysql中? – ripa 2013-04-11 12:31:19
我有上面提到的數組 – Rashmi 2013-04-11 12:32:17