View difference between Paste ID: pt53Z4cb and i8prLAUG
SHOW: | | - or go back to the newest paste.
1
$list = array(
2-
    1 => array(
2+
    1 => (object)array(
3
        'id' => 1,
4
        'parent' => 0
5
    ),
6-
    2 => array(
6+
    2 => (object)array(
7
        'id' => 2,
8
        'parent' => 0
9
    ),
10-
    3 => array(
10+
    3 => (object)array(
11
        'id' => 3,
12
        'parent' => 2
13
    ),
14-
    4 => array(
14+
    4 => (object)array(
15
        'id' => 4,
16
        'parent' => 2
17
    ),
18-
    5 => array(
18+
    5 => (object)array(
19
        'id' => 5,
20
        'parent' => 2
21
    ),
22-
    6 => array(
22+
    6 => (object)array(
23
        'id' => 6,
24
        'parent' => 5
25
    ),
26
);
27
28-
foreach ($list as $id => &$leaf) {
28+
foreach ($list as $leaf) {
29-
	if ($leaf['parent'] !== 0) {
29+
	if ($leaf->parent !== 0) {
30-
		$list[$id]['children'][] = &$leaf;
30+
		$list[$leaf->parent]->children[] = $leaf;
31
        unset($list[$leaf->id]);
32
	}
33
}
34
35
echo "<pre>"; print_r($list); echo "</pre>";