开发者

PHP - use variable as operator

开发者 https://www.devze.com 2023-03-12 02:13 出处:网络
I am trying to get th开发者_运维问答is: if($a[2] > $b[2] && $c[2] < 3) echo \"bingo\";

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

精彩评论

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