我将以下代码部分放在函数中:
$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
和$row
是该函数的参数。
我想将$dynamic_comparison
评估为类似的内容:
if($dynamic_comparison){
//A bunch of code here...
}
我试过了:
if(eval($dynamic_comparison)){
//A bunch of code here...
}
它会抛出错误。如何做到这一点?