BreakBreak Posted February 17, 2007 Share Posted February 17, 2007 Is this possible? $a = "2 >"; $b = 1; if($a $b){ echo "this works"; } So basically i'm trying to make an IF statement out of 2 variables. Is this possible? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Orio Posted February 17, 2007 Share Posted February 17, 2007 No, you cant do that. Give a look to eval(). Orio. Quote Link to comment Share on other sites More sharing options...
BreakBreak Posted February 17, 2007 Author Share Posted February 17, 2007 $a = "2 >"; $b = 1; if($a $b){ echo "this works"; } So, Eval($a $b); if($a $b){ echo "this works"; } Is that right? Quote Link to comment Share on other sites More sharing options...
Orio Posted February 17, 2007 Share Posted February 17, 2007 This way: <?php $a = "2 >"; $b = 1; $str = "if(".$a.$b."){echo 'this works';}"; eval($str); ?> It's important to say that eval() is not recommended. Maybe if you will explain what you are trying exactly to do we will find a better way. Orio. Quote Link to comment Share on other sites More sharing options...
BreakBreak Posted February 17, 2007 Author Share Posted February 17, 2007 Why is it not recommended? What i'm trying to do is pull 2 variables from a sql database as strings and use them in the If statement. One of the strings will always have the operator in it. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
BreakBreak Posted February 17, 2007 Author Share Posted February 17, 2007 Bump. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.