[thelist] Dynamic if statement in PHP

Chris Blessing webguy at mail.rit.edu
Wed Oct 23 14:01:00 CDT 2002


Gustavo-

Try putting the entire IF in the eval() function then:

$teststr = "if($var1 = 'test' && $var2 = 'test2')";

eval($teststr)
	...
}

I know it looks funky.  AFAIK eval doesn't really return anything, it just
executes the code passed to it.

Chris Blessing
webguy at mail.rit.edu
http://www.330i.net

> 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