Re: AW: [PHP] array help

From: Date: Wed, 11 Oct 2000 08:15:25 +0000
Subject: Re: AW: [PHP] array help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-19534@lists.php.net to get a copy of this message
Here is the script. <?php session_start(); session_register("counter"); session_register("basket"); $counter++; $basket=array(); echo"counter 1:-> "; print($counter); # print($PHPSESSID); echo "\n"; if ($submit) { array_push ($basket, $counter); echo"Counter 2:-> $counter"; } echo"<br>"; while (list($key,$value) = each($basket)) { echo"$key : $value<br>"; } ?> <html> <body> <form action="test.php3" method="get"> <input type="hidden" name="PHPSESSID" value="<? echo "$PHPSESSID" ?>"> <input type="submit" name="submit" value="Next"> </form> <A HREF="test.php3?<?=SID?>">click here</A> </body> </html> On Tue, 10 Oct 2000, Jens Wabnitz wrote: > Hi Ajdin, > > What happens if you say $basket=array() - i get an empty array with that. > > Hmm, do you save the value of $counter and send it back to your page as a > parameter. > PHP is stateless so if you recall a page all your values are gone. > > Maybe i'm totally wrong, but your example works here. All it does here is displays different value in the array at position 0 each time I hit the submit. I am missing something but don't know what. Ajdin > > Bye > Jens > > > > -----Ursprungliche Nachricht----- > Von: AJDIN BRANDIC [mailto:abrandic@coventry.ac.uk] > Gesendet: Dienstag, 10. Oktober 2000 17:41 > An: php-general@lists.php.net > Betreff: [PHP] array help > > > Hi, > > I'm trying to add an element to an array each time someone clicks on a > button or page is reloaded. I'm using php4 and array_push doesn't seam > to work the way Perl's array_push does. > > if ($submit) { > array_push ($basket, $counter); > $counter++; > } > > First I cannot just do $basket = array(); to declare the array but have > to do $basket=array(0);. Is there a way arround this? > > The problem with the above code is that new $counter value replaces old > $counter value at array position 1 and the array never grows. > > Can someone tell me how to do this. > > Thanks > > Ajdin > > -- > 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 (#19534) next »