Reputation: 549
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";
}
Upvotes: 0
Views: 1275
Reputation: 1642
You can do like this as well:
echo (25 > 1 ? "success" : ( 25 < 1 ? "success" : "failed")) ;
Upvotes: 1
Reputation: 4587
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';
}
Upvotes: 0