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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

index array how?

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
Hi

Here is my array which works find

$_SESSION['grind_array'][] = array ( 'interest' => $_SESSION['interest'],
'subject' => $_SESSION['subject']
'level' => $_SESSION['level']);


My problem is this how do I get the array index number, as I will need this number in another page to allow the users to delete a certain array item.

For example id someone submits 5 grind_arrays and then they want to remove the second one which is array [1] how can I get this value. Is it something like this.


$_SESSION['grind_array'][] = array ( 'index' => $_SESSION['index'],
'interest' => $_SESSION['interest'],
'subject' => $_SESSION['subject']
'level' => $_SESSION['level']);

How is it possible to delete from an array I was going to use the unset SESSION command to remove the specified array element, is this correct ?

Regards
Graham
 
When you display the array on the other page you must somehow iterate the array. In that process you will get the key.

Code:
foreach ($_SESSION['grind_array'] as $key => $record){
   # $key will be the offset and #record the array of interest, subject etc.
   ... your code here ...
}
In the output create a HTML form element that holds $key so you can use it in the next script that removes elements.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top