PDA

View Full Version : Php if a AND b



iJoe
13-04-2011, 11:43 PM
Hey,

This has been annoying me for a bit now, I've tried googling, just isn't happening for me lol

I want to do something like this

if A and B are true

do this

else

do this

+rep to any help (:

Stephen
13-04-2011, 11:50 PM
if (a && b) {
do this
} else {
do this
}

you mean that? orrrr

N!ck
13-04-2011, 11:59 PM
Yeah, join the statements with && (logical AND) if you want both conditions satiisfied or || for either to be satisfied (logical OR).



$a = true;
$b = false;

if ($a && $b) {
echo "Both are true!";
} else {
echo "One of them or both are not true."; // This will be the result.
}

if ($a || $b) {
echo "At lease one is true"; // This will be the result.
} else {
echo "Neither is true.";
}

iJoe
14-04-2011, 12:11 AM
Thanks a lot, works (:

Want to hide these adverts? Register an account for free!