M.O.S. Studios Posted April 17, 2009 Share Posted April 17, 2009 hey guys, is it possible to place a if() statement's argument in a variable, for example $test="1<=2;"; if($test){echo "it works";}else {echo "it doesn't work";} that will display "it works" but $test="3<=2;"; if($test){echo "it works";}else {echo "it doesn't work";} will display "it doesn't work" I'm assuming if I place the entire if statement in an variable then run it threw eval(); it will work, but i rather not do that. Link to comment https://forums.phpfreaks.com/topic/154507-putting-if-arguments-in-a-var/ Share on other sites More sharing options...
ober Posted April 17, 2009 Share Posted April 17, 2009 That will not work. I think the only reason the first one works is because it only reads the first part of your "equation", which is a 1. Link to comment https://forums.phpfreaks.com/topic/154507-putting-if-arguments-in-a-var/#findComment-812375 Share on other sites More sharing options...
Maq Posted April 17, 2009 Share Posted April 17, 2009 Maybe a ternary? $test= (3 Link to comment https://forums.phpfreaks.com/topic/154507-putting-if-arguments-in-a-var/#findComment-812376 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.