Created
May 23, 2013 06:35
-
-
Save zhoumengkang/5633122 to your computer and use it in GitHub Desktop.
formattree 无限分类
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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