[thelist] Dynamic if statement in PHP

Gustavo Arizpe listas at areaestrategica.com
Wed Oct 23 13:52:01 CDT 2002


El Tuesday, 22 October, 2002, a las 12:41  PM, Chris Blessing escribió:"
> You can use the eval() function
>
> $testString = "$var1 = 'some string' && $var2 = 'some value'";
>
> if(eval($testString)){
> 	...
> }
>
> The value you pass to eval is a string of PHP code, so build the
> conditional statements dynamically ahead of time and pass em in there.
>



Hi,

Eval() Doesn't work either, or at least I can't make it work.


1. This is an example if statement that works:

if ($data[$var0] == $some_array[0] AND $data[$var1] == $some_array[1])

2. This doesn't work, I'd like to generate it through a variable:

$testString = "if (\$data[\$var0] == \$some_array[0] AND \$data[\$var1] ==
\$some_array[1])";

eval ($testString);

---
Apparently eval() only works on one line statemets such as
$testString = (\$string = \"string\";); but I don't know.

There should be a way to generate an if statemente based on some variables,
  shouldn't it?


Thanks


Gustavo




More information about the thelist mailing list