0

I am trying to get this:

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?

1
  • 2
    Becareful using eval...especially with user supplied data. Commented Jun 10, 2011 at 6:51

1 Answer 1

9

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

   $evaledCondition = eval("return $condition;");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.