cliftonbazaar Posted July 18, 2011 Share Posted July 18, 2011 If I run the following code it works fine if($checkBowler['playerID'] == ($match['currentBowler'] or $match['waitingBowler'] or $match[$bowlingTeam.'WicketKeeper'])) { #Check the current, or next, bowler or the wicket keeper but I actually want the opposite and have tried this if($checkBowler['playerID'] != ($match['currentBowler'] or $match['waitingBowler'] or $match[$bowlingTeam.'WicketKeeper'])) { #Don't check the current, or next, bowler or the wicket keeper but this returns no results and it should return 8 Quote Link to comment https://forums.phpfreaks.com/topic/242253-need-opposite-to-this-statement/ Share on other sites More sharing options...
teynon Posted July 18, 2011 Share Posted July 18, 2011 Try: if($checkBowler['playerID'] != ($match['currentBowler'] && $match['waitingBowler'] && $match[$bowlingTeam.'WicketKeeper'])) { #Don't check the current, or next, bowler or the wicket keeper I generally spell out the if statement in this case, personally. It takes more work, but I think it's easier to see / understand (preference). IE: if (($checkBowler['playerID'] != $match['currentbowler']) && ($checkBowler['playerID'] != $match['waitingBowler']) && ($checkBowler[$bowlingTeam.'WicketKeeper'] != $match['currentbowler'])) { Quote Link to comment https://forums.phpfreaks.com/topic/242253-need-opposite-to-this-statement/#findComment-1244101 Share on other sites More sharing options...
AyKay47 Posted July 18, 2011 Share Posted July 18, 2011 Since I do not know what values your $match array stores, this might not work in your case, however you can user the function in_array here $player_id = $checkBowler['playerID']; if(!in_array($player_id, $match)){ // do something } Quote Link to comment https://forums.phpfreaks.com/topic/242253-need-opposite-to-this-statement/#findComment-1244103 Share on other sites More sharing options...
dzelenika Posted July 18, 2011 Share Posted July 18, 2011 opposite means negation ! if(!($checkBowler['playerID'] == ($match['currentBowler'] or $match['waitingBowler'] or $match[$bowlingTeam.'WicketKeeper']))) { #Check the current, or next, bowler or the wicket keeper Quote Link to comment https://forums.phpfreaks.com/topic/242253-need-opposite-to-this-statement/#findComment-1244142 Share on other sites More sharing options...
mikesta707 Posted July 18, 2011 Share Posted July 18, 2011 This line of code may run without a syntax error, but it is NOT doing what you think it is if($checkBowler['playerID'] == ($match['currentBowler'] or $match['waitingBowler'] or $match[$bowlingTeam.'WicketKeeper'])) { when you group that.. strange or statement together, you are producing a boolean value. Remember, or (or ||) is a boolean operation, and returns a boolean value. You are essentially doing this if($checkBowler['playerID'] == true){/// //or if ($checkBowler['playerID'] == false){/// //depending on the value of the that triple or statement now fortunately, PHP will just cast whatever you throw at it on the fly, so if you have a string (as long as its not empty) that statement will be.. ok. It won't behave like you want it to, but if you feed it certain inputs it may make you think it is behaving correctly. It seems like you simply want to check if that value is equal to any of those three values (and then check to negation of that later on) Now, AyKay's advice kind of addresses this problem, but assumes that the three values you are testing that are part of the $match array are its only values. Now, this may be true, in which case you can use in_array like he used, but to be safe I would just stick the three values into another array $arr = ($match['playerID', ... the rest of them you are testing) if (in_array($checkBowler['playerID'], $arr)){//this is what you first test should be ... } if (!in_arrray($checkBowler['playerID'], $arr)){//similar to AyKay's post ... } Quote Link to comment https://forums.phpfreaks.com/topic/242253-need-opposite-to-this-statement/#findComment-1244183 Share on other sites More sharing options...
cliftonbazaar Posted July 19, 2011 Author Share Posted July 19, 2011 Thanks for all the replies. I did Mikesta method and that worked a treat. Quote Link to comment https://forums.phpfreaks.com/topic/242253-need-opposite-to-this-statement/#findComment-1244558 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.