Skip to content

Instantly share code, notes, and snippets.

Created December 17, 2012 05:13
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 anonymous/4315906 to your computer and use it in GitHub Desktop.
Save anonymous/4315906 to your computer and use it in GitHub Desktop.
<?php
$mysql_results = array();
$results = array();
foreach($mysql_results as $item) {
if($item['parent_id']!= 0) {
//如果有 parent_id, 加到 parent里
array_push($results[$item['parent_id']], array('id'=>$item['id'], 'title'=> ......));
} else {
//没有则创建
array_push($results, array('id'=>$item['id'], 'title'=> ......));
}
}
//后面那些点自己补充吧。。
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment