Page 1 of 1

Multiple if empty

Posted: Mon Jan 26, 2004 9:44 am
by Subliminal
need a quick little help... how would i write

if $var1 or $var2 or $var3 is empty do this

???

Code: Select all

<?php if(empty($var1 || $var2 || $var3)){echo"at least one is empty";}else {echo "none are empty";}



?>
Thanks againa guys!

Posted: Mon Jan 26, 2004 9:46 am
by m3mn0n
use OR instead of the double |.

Posted: Mon Jan 26, 2004 9:48 am
by Subliminal
hehehehehe slightly embarrassed

Posted: Mon Jan 26, 2004 9:51 am
by m3mn0n
No worries. You'd laugh at some of the things I did when I was learning. ;)

Posted: Mon Jan 26, 2004 9:51 am
by ol4pr0
That makes me remind mIRC scripting ;-)

Posted: Mon Jan 26, 2004 9:55 am
by JayBird
err...correct me if i am wrong, but...

Code: Select all

if(empty($var1 OR $var2 OR $var3)){
	echo "at least one is empty";
} else {
	echo "none are empty";
}
Will not work...

Would need to be like this

Code: Select all

if(empty($var1) || empty($var2) || empty($var3)){
	echo "at least one is empty";
} else {
	echo "none are empty";
}
Mark

Posted: Mon Jan 26, 2004 9:57 am
by markl999
Correct.

empty() ONLY takes a variable, it's also why things like if(empty(trim($var)) produces a parse error. Also OR and || are exactly the same apart from precedence :o

Posted: Mon Jan 26, 2004 9:58 am
by Subliminal
Wow...

Posted: Mon Jan 26, 2004 11:28 am
by m3mn0n
Note to self: avoid offering help before morning coffee :wink:

Anyway, yes. The if statement would need multiple parenthesis around each variable you are checking and either || or OR between the parenthesis.

The example Bech posted will suffice.

Regards.

Posted: Mon Jan 26, 2004 2:02 pm
by Subliminal
Thanks A Million Guys...