Skip to content

Instantly share code, notes, and snippets.

@zhoumengkang
Created May 23, 2013 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhoumengkang/5633122 to your computer and use it in GitHub Desktop.
Save zhoumengkang/5633122 to your computer and use it in GitHub Desktop.
formattree 无限分类
<?php
/*
* Format Tree
**/
class FORMATTREE
{
function formatTree($arr,$child_key='id',$parent_key='parent_id') {
$tree = array();
foreach ($arr as $val) {
if ( isset($arr[$val[$parent_key]]) ) {
$arr[$val[$parent_key]]['son'][] = &$arr[$val[$child_key]];
} else {
$tree[] = &$arr[$val[$child_key]];
}
}
return $tree;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment