1

我不是来从数据库创建动态菜单的

><ul class="sub">
                        <li class='hidden'>id</li><li><a href="#">a</a></li>
                        <li class='hidden'>id</li><li><a href="#">b</a></li>
                        <li class='hidden'>id</li><li><a href="#">c</a></li>
                        <li class='hidden'>id</li><li><a href="#">d</a></li>
                        <li class='hidden'>id</li><li><a href="#">e</a></li>
 </ul>
>

我有这个来自数据库的数组

数组 ( [0] => 数组 ( [id_zub] => 1 [name] => a )

[1] => Array
    (
        [id_zub] => 2
        [name] => b
    )
[2] => Array
    (
        [id_zub] => 3
        [name] => c
    )
[3] => Array
    (
        [id_zub] => 4
        [name] => b
    )
[4] => Array
    (
        [id_zub] => 5
        [name] => b
    )

)

我有这个功能,我如何插入标签,

函数 ulLiList($array){

foreach($array as $key=> $value){

    if(is_array($value)){
        $this->array_flattern($value);
    }
    else{
        $this->menu .= '<li>'.$key.'</li><li>'.$value.'</li>';
    }
} }
4

1 回答 1

1

您可以测试此函数以动态生成列表。

function createList($lists){
$html_list = "<ul>";
foreach($lists as $list){
 $html_list .= '<li class="hidden">'. $list['id_zub'] .'</li><li><a href="#">'. $list['name'] . '</a></li>';
}
$html_list .= "</ul>";

return $html_list;
}

其中 $lists =

 Array ( 

    [0] => Array ( 
            [id_zub] => 1 
            [name] =>'a' 
    )

    [1] => Array
        (
            [id_zub] => 2
            [name] => 'b'
        )
    [2] => Array
        (
            [id_zub] => 3
            [name] => 'c'
        )
    [3] => Array
        (
            [id_zub] => 4
            [name] => 'd'
        )
    [4] => Array
        (
            [id_zub] => 5
            [name] => 'e'
        )

    )
于 2013-07-14T09:58:36.373 回答