PHP 无限分门别类table转div

WBOY
Release: 2016-06-13 12:49:40
Original
819 people have browsed it

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 />
}
Copy after login



输出的格式为

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




现在想转换成



------解决方案--------------------
$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 />
Copy after login

  • 栏目一
    • 栏目1-1
      • 栏目1-1-1

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!