multidimensional array of n depth from 1-d array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
naresh
Forum Newbie
Posts: 1
Joined: Sat Apr 28, 2007 2:18 am

multidimensional array of n depth from 1-d array

Post by naresh »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi everybody!
i m a new php developer and i m surprised how powerfull php arrays are!
however i facing a problem. i have following structure in my database

Code: Select all

cat_id name        parent_id
1      Category    10
2      computer    1
4      library     1
5      college     1
6      course      5
7      mca         6
8      BCA         6
10     root        NULL
12     laptop      2
now i want to retrieve it and form a multidimentional array on the basis of parent id like:

Code: Select all

$workspace = Array(
    "Category" => Array(
          "Desktop" => Array(
                "Keyboard",
                "Login_Failure",
                "Mouse"
           ),
           "Fax" => Array(
                "Connection",
                "Viewing"
           ),
           "Laptop" => Array(
                 "Software_Install"
           )
     )
);
i have tried a lot but Crying or Very sad
do some one know how to do it?


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

Have you searched for examples in this forum. There are a couple of Q&A's that give examples of what you are asking.
It is suggested that you post some code so we can help from there.
Post Reply