Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple array question

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
0
0
IE
Hi

How can I get the index from the following code

// Set the array
$_SESSION['grind_array'][] = array('Interest' => $_SESSION['Interest'],
'Subject' => $_SESSION['Subject'],
'Level' => $_SESSION['Level'])
);

I need to obtain the internal order in which the element of the above array are stored, subsequent to the removal or delection of some of the elements.

Basically I want to be able to use these indexes in a subsequent page.
For example if the array has 3 elements I want to use index 0,1,2 in the next page.

Regards
 
my understanding is that they are stored in the order in which they are in your code. Interest=0, Subject=1, Level=2.

Why would you want to use the index anyway?
 
$_SESSION['grind_array'][] = array('Interest' => $_SESSION['Interest'],
'Subject' => $_SESSION['Subject'],
'Level' => $_SESSION['Level'])
);

$index=0;
foreach ($_SESSION['grind_array'] as $sub_array)
{
foreach ($sub_array as $key => $value)
{
echo $key." is in the index number ".$index."<Br>";
$index++;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top