php 简单 无级分类 无递归
三 9th
记录一下,以便以后使用。
替换成相应的字段.
代码如下:
View Code PHP
public static function toTree($rows) { if ( !is_array($rows) ) return false; $tree = array(); $index = array(); foreach ( $rows as $row ) { if ( $row['parent_id'] == 0 ) { $i = count($tree); $tree[$i] = $row; $index[$row['type_id']] = & $tree[$i]; } else { $i = count($index[$row['parent_id']]['child']); $index[$row['parent_id']]['child'][$i] = $row; $index[$row['type_id']] = & $index[$row['parent_id']]['child'][$i]; } } return $tree; } |
出处: 马丁博客[http://www.blags.org/]
本文链接地址: http://www.blags.org/php-simple-no-level-classification/
原创文章,转载请注明出处,否则视为侵权。
你同时应该掌握的知识
- wordpress 评论改进 - (2 comments)
- php 安全问题 - (1 评论)
- php filter 安全过滤函数 - (没有评论)
- wordpress 热门文章插件 - (3 comments)
- magento 性能优化 - (7 comments)
- php 程序员 - (3 comments)
- ubuntu 安装 ffmpeg php-ffmpeg - (2 comments)
- 如何提高PHP编程效率 - (4 comments)
- 网站信息查询工具 - (1 评论)
- php+gettext多多语言的探讨 - (2 comments)