Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    RCR
    RCR is offline
    New Coder
    Join Date
    Jul 2012
    Posts
    15
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Need help with Multi-dimensional Session Array

    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?

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,903
    Thanks
    15
    Thanked 226 Times in 226 Posts
    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.
    PHP Code:
    On the builder page
    $myarray 
    = array();
    $_SESSION['myarray'] = $myarray;
    On the other pages
    $myarray 
    $_SESSION['myarray']; 

  • #3
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i think you r ryt...!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •