cetipabo cetipabo - 7 months ago 32
PHP Question

How can I check whether only one out of three variables is not empty?

I have three variables:


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
only? If not, then what's the best way?

The variables all contain text.


You can convert variable into array and exclude empty variables using array_filter(). and use count() after filter

   //only 1 variable is not empty

Check Fiddle link