...

View Full Version : Need help with Multi-dimensional Session Array



RCR
07-29-2012, 08:10 PM
Hi,

I am creating a SESSION based array that will contain the items / quantities that a person can purchase on a given day. If the person has a userid of say 171, and purchases items through a form, then the SESSION array will be populated as:

$_SESSION[171][0]= array('dateval'=>'2012-07-29','item1#'=>12,'quantity1'=>2,'item2#'=>16,'quantity2'=>1,'item3#'=>16,'quantity3'=>1))
$_SESSION[171][1]= array('dateval'=>'2012-07-30','item1#'=>4,'quantity1'=>1,'item2#'=>20,'quantity2'=>2,'item3#'=>16,'quantity3'=>2))

Now through the same form the person may go and modify one of the quantities, say they change the quantity (represented by quantity2), for item2# on 2012-07-30. The change is that instead of 2 units of item2# they choose to buy 1.

So the new values for that day will be:
'dateval'=>'2012-07-30','item1#'=>4,'quantity1'=>1,'item2#'=>20,'quantity2'=>1,'item3#'=>16,'quantity3'=>2

I want to know what I can use to search if an entry for 2012-07-30 already exists in the $_SESSION array and if it exists delete the entire entry corresponding to 2012-07-30 from the $_SESSION array so I can insert this new row for that day instead.

There are so many array functions but I am not sure which one will fit my need.

Will it be easier to do a replacement of values for that day's entries instead. If so how?

DrDOS
07-29-2012, 10:01 PM
Do you really need to make the data part of session? I don't think so, once you build an array it's there for the whole session, you just need to use a $_SESSION variable to reference it on another page.


On the builder page
$myarray = array();
$_SESSION['myarray'] = $myarray;
On the other pages
$myarray = $_SESSION['myarray'];

cascadal
07-30-2012, 10:41 AM
i think you r ryt...!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum