cetipabo cetipabo - 1 year ago 61
PHP Question

How can I check whether only 1 out of 3 vars is not empty in PHP?

I have 3 vars:


I'm actually looking for the best way to check if only one of these 3 var is not empty and the 2 others are empty.

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

The vars all contain text.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download