RE: [PHP] Newbie Question: Variables on the fly
| From: | Tim Winters | Date: | Fri, 28 May 2004 18:30:09 +0000 |
| Subject: | RE: [PHP] Newbie Question: Variables on the fly | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-187157@lists.php.net to get a copy of this message | ||
Steve!!!
This is great!
I had no idea you could use arrays in url variables. That makes everything much easier.
Thanks very much
Tim
At 06:26 AM 28/05/2004, Steve Edberg wrote:
At 2:01 AM -0300 5/28/04, csnm@ns.sympatico.ca wrote:Thanks for the reply Denis, Let me elaborate a bit. I have a php page which I want to pass a series of variables via a url string. eg myPage.php?dataPoint1=10&dataPoint2=20&dataPoint3=30 The thing is I won;t know until runtime how many dataPoints there will be so I have also included 1 additional url variable eg myPage.php?totalDataPoints=3&dataPoint1=10&dataPoint2=20&dataPoint3=30From there I want to take those data points and do several thingswith each of them. The keep things simple lets say I want to multiply each by 3 and then divide it by 2 and put it into a new variable (under the same naming system). eg $xtemp=$HTTP_GET_VARS[totalDataPoints]; do {Strictly speaking, your original question referred to what PHP calls 'variable variables':A line here which will take each dataPoint and multiply by 3 and divide by 2 and assign it to a new variable with the same numbering system (eg $myNewVar1=$HTTP_GET_VARS[dataPoint1]*3/2; $xtemp--;} while ($xtemp>0); Make any more sense? Thanks.http://us3.php.net/manual/en/language.variables.variable.phpHowever, most of what you can do with them can be done more simply with arrays. In your example above, usemyPage.php?dataPoint[]=10&dataPoint[]=20&dataPoint[]=30and you get an array$dataPoint[0]=10 $dataPoint[1]=20 $dataPoint[2]=30The number of data points is count($dataPoint). Seehttp://us3.php.net/manual/en/language.variables.external.phpfor more info on this technique.steve edbergAt 01:24 AM 28/05/2004, Dennis Seavers <deseavers@mindspring.com> wrote:Subject: [PHP] Newbie Question: Variables on the flyMaybe others will catch on to your intention, but I think you need to provide a bit more information. For example, what variables do you want to create (drawn from a file source, or create on the fly)? Where will they come from (a database, perhaps)? You could create a script that creates variables from scratch, following a (hopefully) finite mathematical formula. Or you could manipulate data that already exists, turning this data into some kind of variables. Ultimately, you'll have to give a better of sense of the end result you'd like. Dennis Seavers[Original Message] From: <csnm@ns.sympatico.ca> To: PHP List <php-general@lists.php.net> Date: 05/27/2004 9:17:11 PMTim -- +--------------- my people are the people of the dessert, ---------------+Hello, I'm sure this is a newbie question but I don't know the syntax. I want to create a series of variables within a php script at runtimewitha for loop. eg myVar1 myVar2 myVar3 etc.... What is the proper syntax to do this? Thanks,| Steve Edberg sbedberg@ucdavis.edu | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ |+---------------- said t e lawrence, picking up his fork ----------------+