Re: RE: session

From: Date: Mon, 08 Jan 2001 11:22:16 +0000
Subject: Re: RE: session
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-33212@lists.php.net to get a copy of this message
Regarding the proposed reasoning for it not working from Tim, I find conflicting evidence. For example, try this : $a = array('a','b','c'); foreach ($a as $key => $value) { $a[$key] = $value . $key; } print_r($a); The array does indeed change. It does work on a copy but one still can modify it if one decides to, as demonstrated above. Perhaps a kind soul can explain the meaning of it "working on a copy" as described in the manual with an example on why it matters (possible mishaps). Regarding why negative numbers remain (your array not changing), read the user comments found here : http://www.php.net/manual/function.session-register.php Many discuss this very topic. In fact, this issue looks to be the most popular form of user comment. Regards, Philip On Mon, 8 Jan 2001, Tim Ward wrote: > foreach works on a copy of the array ... therefore, as you found, chnages > are not made to the original. > > see: http://ch.php.net/manual/control-structures.foreach.php > > Tim Ward > Senior Systems Engineer > > Please refer to the following disclaimer in respect of this message: > http://www.stivesdirect.com/e-mail-disclaimer.html > > > > -----Original Message----- > > From: n e t b r a i n [mailto:net-brain@net-brain.net] > > Sent: 07 January 2001 04:24 > > To: php-general@lists.php.net > > Subject: session > > > > > > Hi all, > > I've a problem manipulating a variable stored in session ... > > > > The variable is an array like this: > > > > $item[108]=3; > > $item[56]=1; > > > > //the index is the id_product and var value is the number of items > > > > All works fine except when I try to modify them in bulk, e.g. > > using a simple > > loop like this: > > > > foreach($item as $key=>$val){ > > if($val>0){ > > $item[$key]=$val; > > } else { > > unset($item[$key]); > > } > > } > > session_register("item"); > > > > With this code, no changes are applies ... > > (these values are sent using a simple form via post method > > like this: <input > > type=text name=item[108] ...>). > > > > Any help or suggestion are very appreciated. > > Many thanks in advance. > > max > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#33212) next »