Jump to content

Recommended Posts

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 :(

Link to comment
https://forums.phpfreaks.com/topic/242253-need-opposite-to-this-statement/
Share on other sites

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'])) {

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
}

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
...
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.