Jump to content


Photo

Help with array *SOLVED*


  • Please log in to reply
2 replies to this topic

#1 Pythondesigns

Pythondesigns
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 26 September 2006 - 09:25 PM

Hey,

I have an array like this which is called $CFG.

Array
(
    [online] => 1
    [sitename] => MySite
    [indexurl] => http://mysite.com
    [areas] => Array
        (
            [home] => Array
                (
                    [id] => 1
                    [text] => Home
                    [order] => 0
                    [navshow] => 1
                )

            [profile] => Array
                (
                    [id] => 2
                    [text] => Profile
                    [order] => 1
                    [navshow] => 1
                )

            [jobs] => Array
                (
                    [id] => 3
                    [text] => Jobs
                    [order] => 3
                    [navshow] => 1
                )

            [business] => Array
                (
                    [id] => 4
                    [text] => Business
                    [order] => 4
                    [navshow] => 1
                )

            [finance] => Array
                (
                    [id] => 5
                    [text] => Finance
                    [order] => 5
                    [navshow] => 1
                )

        )

)


As you can see the $CFG[areas] is another array. And then within each again is an array.

Basically each of the values inside the $CFG[areas] are links for a menu Im making and what I want to do is to cycle through them all (theres 5 of them) and display its relevant id.

So at the end I want this...

Home (which links to homes id)
Profile (which links to profiles id)
Jobs (which links to jobs id)
And so on...


How can I do this?

Thanks

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 26 September 2006 - 09:50 PM

foreach ($CFG['areas] as $key => $data) {
     echo "$key : {$data['id']} <br/>";
}


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Pythondesigns

Pythondesigns
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 26 September 2006 - 10:16 PM

Thanks.

It worked perfect :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users