Jump to content

check several variables at once...but only return one


severndigital

Recommended Posts

i would like to do something like this

$var1 = 'yes';
$var2 = '';
$var3 = 'yes';


if(empty($var1) || empty($var2) || empty($var3)){
       echo 'var2 is empty';
}

I know that's not right, but it was the easiest way to explain what I am trying to do.

 

can anyone help?

 

Thanks.

-P

this is a little tough to do without knowing more about the variables. are you able to put them into an array, rather than number them sequentially? if you can't do that, do you have some way of knowing how many variables there are?

Your logic is not far off, assuming the variables are just plain variables and not arrays you could use the isset function to determine if the variable has a value or not.

 

http://us.php.net/isset

 

Simply use it like

 

If (!isset($var1)) { echo "var1 is empty"; }

 

That states if $var1 is NOT SET then echo it is empty.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.