I have the code below taken partially inside a function:
$dynamic_comparison = '';
if(($from == '')&&($to == '')){
$dynamic_comparison = 1;
}else if(($from != '')&&($to != '')){
$dynamic_comparison = '($row >= $from) && ($row <= $to)';
}else if(($from != '')&&($to == '')){
$dynamic_comparison = '($row >= $from)';
}else if(($from == '')&&($to != '')){
$dynamic_comparison = '($row <= $to)';
}
$form, $to and $row are the parameters of the function.
I want to evaluate $dynamic_comparison into something like this:
if($dynamic_comparison){
//A bunch of code here...
}
I tried:
if(eval($dynamic_comparison)){
//A bunch of code here...
}
It throws an error. How to get this right?