Page 1 of 1
using eval() or any otherway to get a value of something lik
Posted: Sun Jan 18, 2004 7:57 am
by pelegk2
i have parms that are sent to the server
i want to read them ina loop
like this
for($i=0;$i<10;++$i){
echo eval('date'+$i);
}
but it isnt working!
why?
thanks in advance
peleg
Posted: Sun Jan 18, 2004 10:19 am
by Meteo
I'm not 100% sure what you're trying to do with that code, with the 'date' string, maybe if you can explain what you want the outcome to be.
firstly, $i is an int variable, and 'date' is a string, the two being added together might not be a good idea.
Posted: Mon Jan 19, 2004 12:46 am
by pelegk2
there is no problem addin an int to string it gives u string an that all the purpose!
second in many languages u sue eval to access variables and arrays dynamicly
which onlly in run time u will know to whome to access beacuse of that for example in javascript u can access an array like this :
eval("arr"+i)[2]=5;
Posted: Mon Jan 19, 2004 12:50 am
by markl999
If you mean you have variables like, $date1, $date2, $date3 etc..and you wish to access them dynamically, then you can do :
for($i=1;$i<10;$i++){
echo ${'date'.$i};
}
Posted: Mon Jan 19, 2004 1:31 am
by pelegk2
thnaks alot!