using eval() or any otherway to get a value of something lik

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

using eval() or any otherway to get a value of something lik

Post 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
User avatar
Meteo
Forum Newbie
Posts: 24
Joined: Sun Jan 18, 2004 10:19 am
Contact:

Post 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.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post 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;
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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};
}
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

thnaks alot!
Post Reply