Maison > Article > développement back-end > PHP 无限分门别类table转div
PHP 无限分类table转div
参考网址
http://www.qunfei.com/htmls/webdevelop/php/2012/0116/819.html
function dafenglei_arr($m,$id)<br /> {<br /> global $class_arr;<br /> global $ppid;<br /> if($id=="") $id=0;<br /> $n = str_pad('',$m,'-',STR_PAD_RIGHT);<br /> $n = str_replace("-"," ",$n);<br /> for($i=0;$i<count($class_arr);$i++){<br /> <br /> <br /> if($class_arr[$i]['classFID']==$id){<br /> echo "<tr>\n";<br /> echo "<td height=\"28\" class=\"font\">".$n."|--<a href=\"?action=edit&id=".$class_arr[$i]['classid']."\">".$class_arr[$i]['className'].$m."</a></td>\n";<br /> echo "</tr>\n"; <br /> dafenglei_arr($m+1,$class_arr[$i]['classid']);<br /> }<br /> <br /> }<br /> <br /> }
$ar = array (<br /> 2 => <br /> array (<br /> 'classid' => '6',<br /> 'classfid' => '0',<br /> 'classname' => '栏目一',<br /> ),<br /> 1 => <br /> array (<br /> 'id' => '7',<br /> 'classfid' => '6',<br /> 'classname' => '栏目1-1',<br /> ),<br /> 0 => <br /> array (<br /> 'classid' => '10',<br /> 'classfid' => '7',<br /> 'classname' => '栏目1-1-1',<br /> ),<br /> );<br /> <br /> echo '<ul>';<br /> foreach($ar as $item) {<br /> if($item['classfid'] == 0) $deep = 0;<br /> $t = substr_count($item['classname'], '-');<br /> if($t < $deep) echo '</li></ul>';<br /> if($t > $deep) echo '<ul>';<br /> echo '<li>'.$item['classname'];<br /> $deep = $t;<br /> }<br /> while($deep--) echo '</li></ul>';<br />