954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Php session array help please

A user will select a tournament to register for, then add a team, then I store the following into a session:

$teamID;
$tournyID;
$gatefee;
$cost;

When they click add to cart I update the session using this:

$_SESSION['cart'][]['team'] = $teamID;
$_SESSION['cart'][]['tournament'] = $tournyID;
$_SESSION['cart'][]['gatefee'] = $gatefee;
$_SESSION['cart'][]['cost'] = $cost;

My array comes out like this:

Array
(
[cart] => Array
(
[] => Array
(
[team] => 2137
[tournament] => 24490
[gatefee] =>
[cost] => 575
)

)

)

As you can see there is no KEY so when someone adds another tournament to their cart it overwrites this one. How can I get the KEY to number 0, 1, 2, etc... with each addition to the cart?

Thanks in advance!!!!

Morty222
Light Poster
29 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 
$_SESSION['cart'][] = array('team'=> $teamID,'tournament'=>$tournyID,'gatefee'=>$gatefee,'cost' => $cost);

Note the code tags!

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You