亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

php - When doing authorization management, an array of unknown depth needs to be traversed (in the form of a tree diagram). How can I write appropriate code?
巴扎黑
巴扎黑 2017-05-16 13:15:40
0
2
515

How to realize the traversal of infinite tree graph? PHP traversal.

巴扎黑
巴扎黑

reply all(2)
小葫蘆
 //php輸出版本:
public static function toTreeHtml($lists = [])
    {
        $string.='<ul class="">';
        foreach ($lists as $key => $value) {
            $string.='<li><input type="checkbox" name="ids[]" />';
            $string.=$value['name'];
            if (count($value['child'])>0){
                $string.=self::toTreeHtml($value['child']);
            }
            $string.='</li>';
        }
        $string.='</ul>'; 
        return $string;
    }
    
    //js輸出版本
    function tree(list,ids){
        var string='';
        string+="<ul class=''>";
        for(i in list){
            
            string+="<li class='"+(list[i].pid==0?"item":"")+"'><label><input "+(in_array(list[i].id,ids)?"checked='checked'":"")+" type='checkbox' value='"+list[i].id+"' name='ids[]' />"+list[i].name+"</label>";
            if(list[i].child){
                string+=tree(list[i].child,ids);
            }
            string+="</li>";
        }
        string+="</ul>";
        return string;
    }
漂亮男人

Recommend a GitHub code to you, https://github.com/jonmiles/b...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template