Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $list = array(
- 1 => array(
- 'id' => 1,
- 'parent' => 0
- ),
- 2 => array(
- 'id' => 2,
- 'parent' => 0
- ),
- 3 => array(
- 'id' => 3,
- 'parent' => 2
- ),
- 4 => array(
- 'id' => 4,
- 'parent' => 2
- ),
- 5 => array(
- 'id' => 5,
- 'parent' => 2
- ),
- 6 => array(
- 'id' => 6,
- 'parent' => 5
- ),
- );
- foreach ($list as $id => &$leaf) {
- if ($leaf['parent'] !== 0) {
- $list[$id]['children'][] = &$leaf;
- }
- }
- echo "<pre>"; print_r($list); echo "</pre>";
Advertisement
Add Comment
Please, Sign In to add comment