开发者

PHP - use variable as operator

I am trying to get th开发者_运维问答is:

if($a[2] > $b[2] && $c[2] < 3) echo "bingo";

But because the condition is retrieved from database, I need to get the whole condition into a variable and then somehow find a way to change the variable back into a condition. I thought it will be something along this line:

$condition = "$a[2] > $b[2] && $c[2] < 3";
$evaledCondition = eval("$condition;");
if($evaledCondition) echo "bingo";

Apparently it didn't work. Am I missing something?


eval() returns NULL unless return is called in the evaluated code

   $evaledCondition = eval("return $condition;");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜