Writing and Reading an Array from a Session.

Discussion in 'PHP' started by oseymour, Oct 29, 2009.

  1. #1
    I have the following array

    
    <?php foreach ($order->getItems() as $item) { ?>
        "<?php echo $data['orderNumber']?>", 
        "<?php echo $item->getProductNumber()?>", 
        "<?php echo $item->getName()?>", 
        "<?php echo $item->getUnitPrice()?>",    
        "<?php echo $item->getQuantity()?>"                                      
    <?php } ?>
    
    PHP:
    I need help writing the follow information into a session and then reading the same info from a session.

    I tried using
    $_SESSION['neworders']=$order; 
    PHP:
    but that didn't work.

    The array can contain one product or multiple products.
     
    oseymour, Oct 29, 2009 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    To add to session:
    $_SESSION['neworders'] = serialize($order);
    PHP:
    to get back from session
    $order = unserialize($_SESSION['neworders']);
    PHP:
     
    JAY6390, Oct 29, 2009 IP
  3. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #3
    And don't forget to put this line before any output is sent to browser:
    
    session_start();
    
    PHP:
     
    AsHinE, Oct 29, 2009 IP
  4. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    AsHinE why always before me :D
     
    xenon2010, Oct 30, 2009 IP