Page 1 of 1

php equivalent to javascript eval()? (or just a solution =o)

Posted: Mon Nov 25, 2002 9:34 pm
by Axium
I'm using variables passed in through a form to generate pages of data dynamically (they're all on separate layers linked together, and I don't know how many pages beforehand). When I make the url for the link variables that represent different pages get numbers appended to them: &name0=name...&name1=name2...etc.

Anyway.

On the receiving end I'm running into the problem that I have to know the variable name before I try to output it, but I don't want to hardcode it.

I'd want something to the effect of:

Code: Select all

for ($i = 0; $i < $noofelements; $i++)
   echo ($name+$i);
But that will only give me the contents of $name + the integer 1, I want the contents of $name1.

In javascript you can use the eval() function to turn a string into an executable statement, I'm just wondering if there's an equivalent in php or someone knows how to help me with this problem.

Thanks ahead of time,
Justin

Posted: Mon Nov 25, 2002 10:16 pm
by mydimension
its the eval() function. and works the same way i think. http://www.php.net/manual/en/function.eval.php

Posted: Mon Nov 25, 2002 10:38 pm
by volka
also note http://www.php.net/manual/en/language.v ... riable.php

Code: Select all

<?php
$name0 = 'test';
$name1 = 'value';
$noofelements = 2;

for ($i = 0; $i < $noofelements; $i++)
   echo ${'name'.$i}, '<br/>';
?>