Array to Array pushing in Zend Session object

Posted by kate-koopy on Stack Overflow See other posts from Stack Overflow or by kate-koopy
Published on 2010-06-05T10:03:14Z Indexed on 2010/06/05 10:12 UTC
Read the original article Hit count: 207

Filed under:
|

Hello! I have some example of pushing array to array in session object:

   class someClass extends someOtherOne {

...////// some other code here that starts session and  creates namespace

    public function __add2Session($a,$b) {  

    $namespc = $this -> __getnewNameSpace(); //returns a Zend Session Namesapce (object)

        if (!isset($namespc -> {$a})) { $namespc -> {$a} = array(); }

            array_push($namespc -> {$a}, $b);

        }

    }


.../////////////


$item=array(1=>"one",2=>"two",3=>"three",4=>"four",5=>"five",6=>"six",7=>"seven");

$k = new someClass();
$cart = new Zend_Session_Namespace('Cart');
$k -> __add2Session("items",$item);

The result is when I reload the page several times - the value of $cart -> items in the session gets overwritten and not populated. Can somebody explain why it occurs and how do I fix this?

I want to have $cart -> items to be an "array in array" like:

$cart -> items = array(array(1=>"one",2=>"two"), array(1=>"two",2=>"three"));

© Stack Overflow or respective owner

Related posts about php

Related posts about zend-framework