php 无限分级算法
无限分级算法 **[PHP]代码**[代码片段(30行)]
[PHP]代码
<?php //无限分级分类 //来源: htttp://aiyooyoo.com header('Content-type:text/html; charset=UTF-8'); $conn = mysql_connect('localhost', 'root', '123456'); mysql_select_db('xsphp'); mysql_query('SET NAMES utf8'); $result = mysql_query('SELECT id,fid,name FROM cat ORDER BY id'); $rows = array(); while ($row = mysql_fetch_assoc($result)) { $rows[$row['id']] = $row; } $t = array(); foreach ($rows as $id => $item) { if ($item['fid']) { $rows[$item['fid']][$item['id']] = &$rows[$item['id']]; $t[] = $id; } } foreach($t as $u) { unset($rows[$u]); } print_r($rows);
- 上一篇:php 新鲜出炉的新浪PHP框架纯净版
- 下一篇:php 几种获取路径的后缀名方法
收藏文章
精彩图集
精彩文章