Re: store array into session variable and get it back later

From: Date: Wed, 01 Oct 2008 16:45:24 +0000
Subject: Re: store array into session variable and get it back later
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-281289@lists.php.net to get a copy of this message
This is what i did afterall, but when i unserialize it like this way: $bci = unserialize($_SESSION['bc']);
    foreach($bci as $key=>$value)
    {
        echo "bci : ".$key;
        echo "<br/>";
    }
i get absolutely the same result as the code below. in fact $key returns me the 2 variables member of the Class. but not the value stored inside them. any idea ? so here is what i've decided to use:
    
for ($row=0;$row<=count($bci->crumb);$row++) {
        echo "<br/>value[$row]['name'] :
".$bci->crumb[$row]['name']."<br/>";
        echo "<br/>value[$row]['link'] :
".$bci->crumb[$row]['link']."<br/>";
        echo "<br/>value[$row]['id'] : ".$bci->crumb[$row]['id']."<br/>";
} and it works like a charm. but how can i optimize it ? i mean foreach could do the work better ?
Since it is not necessary to store the object in the session at least AFAIK I wonder why don't you just store a simple array. You will not need to worry for anything. -- Thodoris

« previous php.general (#281289) next »