Re: Array as a session variable - Bug ?

From: Date: Fri, 11 Aug 2000 14:40:40 +0000
Subject: Re: Array as a session variable - Bug ?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-11333@lists.php.net to get a copy of this message
eovidiu@rds.ro ("Ovidiu EFTIMIE") writes: > Greetings, > I'm working with php 4.0(1-08-2000 snapshot) and I use an array as an > session variable.I've noticed that I can read the array only once, and at > the second read the array is empty . > For example > $number=4; > for($i=0;$i<$number;$i++){ > echo $i; > //ses_packs - the session array > while(list(,$val)=each($ses_packs)){ > pg_exec("insert into tblc(pack) values('".$val."')"); > } > } > At the first iteration the values are inserted but at the second one the > ses_packs is empty. > Of course I can use an work around but I was wondering if this a normal > behaviour or it's a bug. It's not empty, you've just got to the end of it. You need to go back to the start of the array with reset(). It's in the manual at http://uk.php.net/manual/function.reset.php3 $number=4; for($i=0;$i<$number;$i++){ echo $i; //ses_packs - the session array reset($ses_packs); while(list(,$val)=each($ses_packs)){ pg_exec("insert into tblc(pack) values('".$val."')"); } } -- Robin Vickery............................................... Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK Email: robin@planet-three.net Phone: +44 (0)794 670 6395

« previous php.general (#11333) next »