PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Subliminal
Forum Commoner
Posts: 40 Joined: Thu Oct 23, 2003 8:12 pm
Post
by Subliminal » Mon Jan 26, 2004 9:44 am
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!
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Mon Jan 26, 2004 9:46 am
use OR instead of the double | .
Subliminal
Forum Commoner
Posts: 40 Joined: Thu Oct 23, 2003 8:12 pm
Post
by Subliminal » Mon Jan 26, 2004 9:48 am
hehehehehe slightly embarrassed
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Mon Jan 26, 2004 9:51 am
No worries. You'd laugh at some of the things I did when I was learning.
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Jan 26, 2004 9:51 am
That makes me remind mIRC scripting
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Jan 26, 2004 9:55 am
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
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Mon Jan 26, 2004 9:57 am
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
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Mon Jan 26, 2004 11:28 am
Note to self: avoid offering help before morning coffee
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.
Subliminal
Forum Commoner
Posts: 40 Joined: Thu Oct 23, 2003 8:12 pm
Post
by Subliminal » Mon Jan 26, 2004 2:02 pm
Thanks A Million Guys...