Re: creating an array in a while loop

From: Date: Mon, 16 Oct 2000 12:42:49 +0000
Subject: Re: creating an array in a while loop
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-20358@lists.php.net to get a copy of this message
I'm trying .. bvut not getting very far .. this is basically the result i'mlooking for while ($row=$this->db_fetch_array($result)){ $select_array[]="$row["lan"]=>$row["name"]"; } I'm getting errors .. and I don't know arrays that well to know what I'm doing wrong .. please help henti On Mon, Oct 16, 2000 at 12:34:49PM +0100, Clive Hughes wrote: > 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 (#20358) next »