Convert 2 dimensional array to multidimensional

Viewed 214

How do i convert this 2 dimensional array to tree i.e

This

Array
(
    [0] => Array
        (
            [id] => 1
            [name] => User
            [parent_id] => 0
        )

    [1] => Array
        (
            [id] => 2
            [name] => Product
            [parent_id] => 0
        )

    [2] => Array
        (
            [id] => 3
            [name] => Login
            [parent_id] => 1

        )

    [3] => Array
        (
            [id] => 4
            [name] => Forgot Password
            [parent_id] => 3

        )
}

To

Array
(

    [1] => User => Array
    (
        [3] => Login => Array
        (
            [4] => Forgot Password
        )
    }
    [2] => Product
}

i.e create childs based on parent id's

1 Answers
Related