Re: creating an array in a while loop

From: Date: Mon, 16 Oct 2000 11:34:49 +0000
Subject: Re: creating an array in a while loop
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20342@lists.php.net to get a copy of this message
Hentis, Do you mean you want to keep appending to the array(s)? If so, use empty square brackets, e.g. $myArray[] = "1"; $myArray[] = "2"; $myArray[] = "5"; and so on. The example above creates $myArray with 3 elements ({1, 2, 5}) --Clive ----- Original Message ----- From: <hentis@twilyt.com> To: "PHP list" <php-general@lists.php.net> Sent: Monday, October 16, 2000 12:21 PM Subject: [PHP] creating an array in a while loop > hi all > > I've been trying to get around this for a while now .. but I seem to be stumped. > > I have a result from a query .. which I can fetch into an array as normal > > I want to creat an array with selected fields from the result. something like this. > > $result=mysql_query($query); > while ($row=mysql_fetch_array($result)){ > $key=$row["element1"]; > $value=$row["element2"]; > $endarray[$key]=$value; > } > > I dont't knwo how to do this .. in code .. bu i have a general idea of creating an empty array with numrows as size > and then add each key/val pair in .. but I'm noot sure how to do it .. > > can somebody please lend a hand > > HEnti > > > -- > 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 (#20342) next »