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: 
```
$counter=0;
$counter+= empty($var1) ? 0:1;
$counter+= empty($var2) ? 0:1;
$counter+= empty($var3) ? 0:1;

if($counter==1)
   echo "Exactly 2 are empty";

```

**[Fiddle](https://eval.in/641962)**

Or you can simply do

```
var_dump(count(array_filter(array($var1,$var2,$var3)))==1);

```

**[Fiddle](https://eval.in/641979)**
Try this:

```
$temp_array = array($var1,$var2,$var3);
$temp_count = count(array_filter($temp_array, 'strlen'));
if($temp_count ==1){
    echo "1 variable is not empty";
}
else
{
    echo "total empty variable  is = ".$temp_count;
}

```

**[DEMO](https://3v4l.org/17k7K)**