Imad Posted June 15, 2008 Share Posted June 15, 2008 Hi guys, quick question. I'm trying to get an if function to work if two variables don't equal each other. What do I need to add? Best Regards. Quote Link to comment https://forums.phpfreaks.com/topic/110288-if-a-vairable-doesnt-equal-another-help/ Share on other sites More sharing options...
wildteen88 Posted June 15, 2008 Share Posted June 15, 2008 Use the not equal to comparison operator (!=) if($var1 != $var2) { // no match } else { // match } Quote Link to comment https://forums.phpfreaks.com/topic/110288-if-a-vairable-doesnt-equal-another-help/#findComment-565894 Share on other sites More sharing options...
webbiedave Posted June 15, 2008 Share Posted June 15, 2008 Just keep in mind PHP's type conversion when comparing strings and numbers. For instance: $a = 3; $b = '3d'; echo ($a != $b); will evaluate to false, while: echo ($a !== $b); will evaluate to true. For more info, see: http://us.php.net/operators.comparison Quote Link to comment https://forums.phpfreaks.com/topic/110288-if-a-vairable-doesnt-equal-another-help/#findComment-565938 Share on other sites More sharing options...
Imad Posted June 15, 2008 Author Share Posted June 15, 2008 Thanks guys. It's exactly like perl code. Quote Link to comment https://forums.phpfreaks.com/topic/110288-if-a-vairable-doesnt-equal-another-help/#findComment-565941 Share on other sites More sharing options...
BrianM Posted June 15, 2008 Share Posted June 15, 2008 And it taste just like chicken! Quote Link to comment https://forums.phpfreaks.com/topic/110288-if-a-vairable-doesnt-equal-another-help/#findComment-565944 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.