PHP使用OR但在两种情况都为真时避免运行

I am running into a problem.

I am using a recursive function that will pass the case to run to another function.

The problem is that I am doing the following:

if ($case == 1 || count($matching) == 0 && $case == NULL)
    do something....

So 'do something' only if the $case == 1 OR only if $matching > 0 and $case == NULL

Looks like that PHP does not correctly understand it.

In fact if $case == 1 and $matching > 0 it will run anyway the 'do something' even if it should not, because I said to it to run 'do something' when $matching > 0 only if $case is also == NULL.

What's wrong?

How do I tell to PHP to run only if $case == 1 OR ONLY if $matching > 0 AND also $case == NULL ?

Using the XOR logical operator (XOR comes from eXclusive OR):

if ($case == 1 xor ($matching > 0 && $case == null)) { ... }

Try this, this will ensure that last 2 conditions are grouped together and the result of those 2 is true if and only if both of them are true:

if ($case == 1 || (count($matching) > 0 && $case == NULL)){
}

In PHP, && takes precedent over ||, so you need to add brackets:

($case == 1 || (count($matching) == 0 && $case == NULL) )