Last active
June 28, 2018 01:35
-
-
Save tqyq/7fbf1e306acabbce42a4 to your computer and use it in GitHub Desktop.
php generate json tree from array
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
function genTree($items, $idkey='_id'){ | |
$tree = array(); | |
foreach($items as $item){ | |
if(isset($items[$item['pid']])){ | |
$items[$item['pid']]['son'][] = &$items[$item[$idkey]]; | |
}else{ | |
$tree[] = &$items[$item[$idkey]]; | |
} | |
} | |
return $tree; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment