当前位置:Gxlcms > PHP教程 > PHP无限分门别类table转div

PHP无限分门别类table转div

时间:2021-07-01 10:21:17 帮助过:10人阅读

PHP 无限分类table转div

参考网址
http://www.qunfei.com/htmls/webdevelop/php/2012/0116/819.html


function dafenglei_arr($m,$id)
{
global $class_arr;
global $ppid;
if($id=="") $id=0;
$n = str_pad('',$m,'-',STR_PAD_RIGHT);
$n = str_replace("-"," ",$n);
for($i=0;$i

if($class_arr[$i]['classFID']==$id){
echo "\n";
echo "".$n."|--".$class_arr[$i]['className'].$m."\n";
echo "\n";
dafenglei_arr($m+1,$class_arr[$i]['classid']);
}

}

}



输出的格式为

栏目1
栏目1-1
栏目1-2
栏目1-3
栏目1-3-1




现在想转换成


  • 栏目一

    • 栏目1-1

    • 栏目1-2

    • 栏目1-3

      • 栏目1-3-1





  • ...........等类似




------解决方案--------------------
$ar = array (
2 =>
array (
'classid' => '6',
'classfid' => '0',
'classname' => '栏目一',
),
1 =>
array (
'id' => '7',
'classfid' => '6',
'classname' => '栏目1-1',
),
0 =>
array (
'classid' => '10',
'classfid' => '7',
'classname' => '栏目1-1-1',
),
);

echo '
    ';
    foreach($ar as $item) {
    if($item['classfid'] == 0) $deep = 0;
    $t = substr_count($item['classname'], '-');
    if($t < $deep) echo '
';
if($t > $deep) echo '
    ';
    echo '
  • '.$item['classname'];
    $deep = $t;
    }
    while($deep--) echo '
';
  • 栏目一
    • 栏目1-1
      • 栏目1-1-1

人气教程排行