RE: [PHP] Dynamic Arrays?

From: Date: Thu, 15 Mar 2001 14:23:58 +0000
Subject: RE: [PHP] Dynamic Arrays?
Groups: php.general 
Request: Send a blank email to php-general+get-44030@lists.php.net to get a copy of this message
> -----Original Message----- > From: RealGM [mailto:webmaster@realgm.com] > Sent: Thursday, March 15, 2001 3:38 AM > To: php-general@lists.php.net > Subject: [PHP] Dynamic Arrays? > > > Hi, > > I have a bit of a dilemma. > > I have a number of array attributes, eg. $arrayname["var1"], > $arrayname["var2"], $arrayname["var2"], etc. up to 58, and I > want to write these into the database. > > What I am hoping to do is create a counter that goes through > the insert routine, updating the numerical value of "var". > The problem is.. everything I have tried hasn't worked. > > I have tried things like... > > $counter=1; > > $arrayname[["var".$counter1]]; > $arrayname["var$counter1"]; > > ...and variations thereof. Everything I have tried has failed. How about just foreach ($arrayname as $arrayval) { do stuff with $arrayval } Or, if it's also important for you to know that you're dealing with the value of "var1"... foreach ($arrayname as $arraykey=>$arrayval) { do stuff with $arraykey and $arrayval } --- Mark Roedel | "I know the answer! The answer lies within the Systems Programmer | heart of all mankind! The answer is twelve?!? LeTourneau University | I think I'm in the wrong building." Longview, Texas, USA | -- Peppermint Patty (Charles Schultz)

« previous php.general (#44030) next »