...

View Full Version : First Item in Array



thesavior
07-06-2007, 04:59 PM
I have an array, set up like this:


$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.

GJay
07-06-2007, 05:09 PM
current() http://php.net/current

thesavior
07-06-2007, 05:15 PM
when i put in:


$this->curr_file = current($this->navigation_array)

$this->curr_file equals "array"

print_r of navigation_array is:



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
)

)

Brandoe85
07-06-2007, 09:06 PM
current(current())
$first = current(current($this->navigation_array));

Good luck;

GJay
07-06-2007, 10:36 PM
it depends which 'Home' you want,


key($this->navigation_array);

will also give you 'Home'



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum