Question: I have three variables:

```
$var1
$var2
$var3

```

I'm actually looking for the best way to check if **only one** of these three variables is not empty and the **two others** are empty.

Is that possible to do this with one `if` only? If not, then what's the best way?

The variables all contain text.

Answer: 
Booleans return 0 and 1 with array\_sum() 

```
if (array_sum(array(empty($var1), empty($var2), empty($var3))) == 1)
{
    echo "one is empty" ;
}

```

ETA:
This is a simpler way:

```
if (!empty($var1) + !empty($var2) + !empty($var3) == 1) {
    echo "1 is not empty" ;
}

```

ETA 2: We don't need the negative signs

```
if (empty($var1) + empty($var2) + empty($var3) == 2) {
    echo "1 is not empty" ;
}

```
Bitwise XOR is great for this:

```
$var1 ^ $var2 ^ $var3

```

You *might* have trouble if the variables don't cast to boolean easily, in which case you'd need to do `empty($var)` on each of them.

Boom. Zero `if`s.

**Update**

Oops, if they are *all* not empty, true ^ true ^ true == true

You'll need to check against all of them being true:

```
($var1 ^ $var2 ^ $var3) && !($var1 && $var2 && $var3)

```