Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    First Item in Array

    I have an array, set up like this:

    PHP Code:
    $this->navigation_array['Home'] = array('text' => 'Home''act' => 'Home''redirect' => 'No''active' => 'Home''link' => 'index.php?act=home''default' => 'Info');
            
    $this->navigation_array['Forums'] = array('text' => 'Forums''act' => 'Forums''redirect' => 'No''active' => 'Forums''link' => 'index.php?act=forums''default' => 'Info');
            
    $this->navigation_array['Users'] = array('text' => 'Users''act' => 'Users''redirect' => 'No''active' => 'Users''link' => 'index.php?act=users');
            
    $this->navigation_array['Config'] = array('text' => 'Configuration''act' => 'Config''redirect' => 'No',  'active' => 'Config''link' => 'index.php?act=config'); 
    I want to find the first item inserted into the array, namely "Home".

    What is the fastest way to just call the first entry? You cant use
    $this->navigation_array[0] in this case because the keys are text not numbers.

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    when i put in:

    PHP Code:
    $this->curr_file current($this->navigation_array
    $this->curr_file equals "array"

    print_r of navigation_array is:

    Code:
    Array
    (
        [Home] => Array
            (
                [text] => Home
                [act] => Home
                [redirect] => No
                [active] => Home
                [link] => index.php?act=home
                [default] => Info
            )
    
        [Forums] => Array
            (
                [text] => Forums
                [act] => Forums
                [redirect] => No
                [active] => Forums
                [link] => index.php?act=forums
                [default] => Info
            )
    
        [Users] => Array
            (
                [text] => Users
                [act] => Users
                [redirect] => No
                [active] => Users
                [link] => index.php?act=users
            )
    
        [Config] => Array
            (
                [text] => Configuration
                [act] => Config
                [redirect] => No
                [active] => Config
                [link] => index.php?act=config
            )
    
    )
    Last edited by thesavior; 07-06-2007 at 05:19 PM.

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    current(current())
    $first = current(current($this->navigation_array));

    Good luck;

  • #5
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    it depends which 'Home' you want,
    PHP Code:
    key($this->navigation_array); 
    will also give you 'Home'
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •