I have stored conditions in database string format. ex: ((25>1)||(25<1))
How can I pass this string to if
condition statement. I tried, but it's not working. I have used eval()
function, but it's not working.
$con=eval("return ((25>1)||(25<1))");
if($con){
echo "success";
}
else{
echo "failed";
}
您也可以这样做:
echo (25 > 1 ? "success" : ( 25 < 1 ? "success" : "failed")) ;
You are missing a semicolon in your eval()
. Strings passed into eval()
still must be valid PHP, which will need an ;
.
$con = eval('return ((25>1)||(25<1));');
if($con) {
echo 'success';
} else {
echo 'failed';
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.