0
我在ul裏有我的代碼的樹結構。現在我有一個小問題,奏響了..下面是我的數組在UI中的UI li樹結構
Array
(
[5] => Array
(
[parent] => 0
[name] => Kitchen
[cat_id] => 5
[slug] => kitchen
[children] => Array
(
[6] => Array
(
[parent] => 5
[name] => Knife
[cat_id] => 6
[slug] => knife
)
)
)
[6] => Array
(
[parent] => 5
[name] => Knife
[cat_id] => 6
[slug] => knife
)
[13] => Array
(
[parent] => 0
[name] => Stainless Steel
[cat_id] => 13
[slug] => stainless
[children] => Array
(
[18] => Array
(
[parent] => 13
[name] => Plate
[cat_id] => 18
[slug] => plate
)
)
)
[16] => Array
(
[parent] => 0
[name] => Cloth
[cat_id] => 16
[slug] => cloth
)
[17] => Array
(
[parent] => 0
[name] => Dinner Set
[cat_id] => 17
[slug] => dinner-set
)
[18] => Array
(
[parent] => 13
[name] => Plate
[cat_id] => 18
[slug] => plate
)
[19] => Array
(
[parent] => 0
[name] => Plastic
[cat_id] => 19
[slug] => plastic
[children] => Array
(
[20] => Array
(
[parent] => 19
[name] => Cups
[cat_id] => 20
[slug] => cups
)
)
)
[20] => Array
(
[parent] => 19
[name] => Cups
[cat_id] => 20
[slug] => cups
)
[26] => Array
(
[parent] => 0
[name] => Items
[cat_id] => 26
[slug] => items
)
)
而且我的PHP代碼如下:
function toULlistproduct($arr,$shop_url='')
{
$html = '<ul >'.PHP_EOL;
foreach ($arr as $v)
{
$html .= '<li><a href="'.site_url().$shop_url.'/category/'.$v['slug'].'" id="' . $v['cat_id'] . '" >' . $v['name'].'</a>' ;
if (array_key_exists('children', $v))
$html .= toULlistproduct($v['children'],$v['cat_id'],$shop_url);
$html .= '</li>'.PHP_EOL;
}
$html .= '</ul>'.PHP_EOL;
return $html;
}
我的HTML看起來像這樣:
<ul>
<li><a id="5" href="http://localhost/myproject/category/kitchen">Kitchen</a><ul>
<li><a id="6" href="http://localhost/myproject/category/knife">Knife</a></li>
</ul>
</li>
<li><a id="6" href="http://localhost/myproject/category/knife">Knife</a></li>
<li><a id="13" href="http://localhost/myproject/category/stainless">Stainless Steel</a><ul>
<li><a id="18" href="http://localhost/myproject/category/plate">Plate</a></li>
</ul>
</li>
<li><a id="16" href="http://localhost/myproject/category/cloth">Cloth</a></li>
<li><a id="17" href="http://localhost/myproject/category/dinner-set">Dinner Set</a></li>
<li><a id="18" href="http://localhost/myproject/category/plate">Plate</a></li>
<li><a id="19" href="http://localhost/myproject/category/plastic">Plastic</a><ul>
<li><a id="20" href="http://localhost/myproject/category/cups">Cups</a></li>
</ul>
</li>
<li><a id="20" href="http://localhost/myproject/category/cups">Cups</a></li>
<li><a id="26" href="http://localhost/myproject/category/items">Items</a></li>
</ul>
現在我想顯示一個href是我的問題:即
我只是想顯示href網址如下圖所示:
<li><a id="6" href="http://localhost/myproject**/category/knife**">Knife</a></li>
this should be display like below
<li><a id="6" href="http://localhost/myproject/**category/kitchen/knife**">Knife</a></li>
我只是想修改一個href網址只
我是否正確理解唯一的問題是您的鏈接不包含父類別? – rdrkt
是的..我需要添加家長catgories slug到我的鏈接 – Aaru