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. Link to comment https://forums.phpfreaks.com/topic/38890-is-this-possible-variables-in-an-if-statement-please-help/ 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. Link to comment https://forums.phpfreaks.com/topic/38890-is-this-possible-variables-in-an-if-statement-please-help/#findComment-187021 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? Link to comment https://forums.phpfreaks.com/topic/38890-is-this-possible-variables-in-an-if-statement-please-help/#findComment-187031 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. Link to comment https://forums.phpfreaks.com/topic/38890-is-this-possible-variables-in-an-if-statement-please-help/#findComment-187063 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. Link to comment https://forums.phpfreaks.com/topic/38890-is-this-possible-variables-in-an-if-statement-please-help/#findComment-187134 Share on other sites More sharing options...
BreakBreak Posted February 17, 2007 Author Share Posted February 17, 2007 Bump. Link to comment https://forums.phpfreaks.com/topic/38890-is-this-possible-variables-in-an-if-statement-please-help/#findComment-187302 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.