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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



how about:

$bci = $_SESSION['bc'];

foreach($bci->crumb as myCrumb)
{
    echo "<br/>value['name'] :".$myCrumb['name']."<br/>";
    echo "<br/>value['link'] :".$myCrumb['link']."<br/>";
    echo "<br/>value['id'] : ".$myCrumb['id']."<br/>";
}

You are wanting to loop through the crumbs rather than looping objects.
There is only one object you are sending over through  the session and
multiple crumbs right?


On Wed, 2008-10-01 at 17:04 +0200, Alain Roger wrote:
> >
> >
> >>  later on i try to use the content of this array, bt without success.
> >>> Here is what i do:
> >>>
> >>> $bci = array($_SESSION['bc']);
> >>>
> >>>> array_push($bci,$_SESSION['bc']);
> >>>>
> >>>> foreach($bci as $key=>$value)
> >>>> {
> >>>>  echo "bci : ".$bci[$key]['name'];
> >>>>  echo "<br/>";
> >>>> }
> >>>>
> >>>>
> >>> how can i get the 'name' value for each row in this session stored array
> >>> ?
> >>> thx.
> >>>
> >>>  ...
> >>
> >> The function you need to look into is called "serialize".
> >>
> >> http://www.php.net/manual/en/function.serialize.php
> >>
> >> //frank
> >>
> > 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 ?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux