Issue
I have stored some rules/logic in a column in database. With that retried rule I want to make it a condition. Since the retrieved rule is returning as string value my condition gives me TRUE for always.
let's say
$www = $rule->logic; // $rule ->logic = (20 > 3) and (20 < 5)
if($www ){
$this->logger->debug('commision granted');
}else{
$this->logger->debug('commision noooo');
}
However If I simply use if ((20 > 3) and (20 < 5))
Then I can get a correct answer.
I have no idea how to convert $www ?
Solution
You can use PHP eval()
to execute expression:
$www = $rule->logic; // $rule ->logic = (20 > 3) and (20 < 5)
if(eval("return $www;")){
echo 'commision granted';
}else{
echo 'commision noooo';
}
Answered By - B. Desai
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.