Re: If statement w/ multiple conditions

From: Date: Tue, 26 Nov 2002 15:45:36 +0000
Subject: Re: If statement w/ multiple conditions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-126101@lists.php.net to get a copy of this message
--- Ernest E Vogelsinger <ernest@vogelsinger.at> wrote: > At 13:50 26.11.2002, ed@home.homes2see.com said: > >if ($lineone && $linetwo && $linethree && $linefour = "") > > Your expression yields true if 1-3 are not-empty AND four is an > empty string. Actually, this expression yields true when $lineone, $linetwo, and $linethree are all true. The variable $linefour is just being set to the empty string. Don't confuse boolean tests with tests for whether a string is empty. Yes, an empty variable will evaluate as false, but so will a variable containing 0 or set to false. > All empty: > !($lineone || $linetwo || $linethree || $linefour) > --or-- > !$lineone && !$linetwo && !$linethree && !$linefour > All set: > $lineone && $linetwo && $linethree && $linefour Same problem here. Try these conditionals with the following values: $lineone = 0; $linetwo = 0; $linethree = 0; $linefour = 0; Something like this will probably work: $all = $lineone . $linetwo . $linethree . $linefour; if (empty($all)) { echo "All lines are empty"; } else { echo "All lines are not empty"; } Chris

« previous php.general (#126101) next »