Re: if(($var && $var < $othervar) || (statement like first) || ( other statement))

From: Date: Thu, 15 Jun 2000 19:24:23 +0000
Subject: Re: if(($var && $var < $othervar) || (statement like first) || ( other statement))
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-1994@lists.php.net to get a copy of this message
Hi Lewis, At 02:13 PM 6/15/00 -0400, Lewis Bergman wrote:
(($var && $var < $othervar) || (statement like first) || ( other statement)) Forgive me but I searched the manuals and evidently I am so far off I don't know where to look. The script which is the subject of the questions to follow: if (($clients[$i]["views"] && $clients[$i]["views"] < $clients[$i]["views_used"]) ||
      ($clients[$i]["clicks"]  && $clients[$i]["clicks"] < $clients[$i]["clicks_used"]) ||
      (isset($clients[$i]["days"]) && $clients[$i]["days"] < 0))
      {
do whatever Q. 1. I know what the && is for from the maual. both $a and $b are true result is true. But what does if ($a && $a) do. It must be different because this script I am trying to find a problem with absolutely will do nothing without it.
The associativity of the operators changes how this line works. && has lower precedence than <, so $a < $b is tested before $a && $a The line is not:
        $a && $a
it is:
        $a && ($a < $b)
Here is a more readable version of the same code. Note that this version is also less efficient. The original version of the code requires less time to evaluate. $any_views_left = $clients[$i]["views"] AND ($clients[$i]["views"] < $clients[$i]["views_used"]); $any_clicks_left = $clients[$i]["clicks"] AND ($clients[$i]["clicks"] < $clients[$i]["clicks_used"]); /*
        This line was (isset($clients[$i]["days"]) && $clients[$i]["days"] < 0),
        however if $clients[$i]["days"] is not set, it will evaluate to 0.
        If this is the case then $clients[$i]["days"] <0 would fail anyway
*/ $any_days_left = $clients[$i]["days"] < 0; if ($any_views_left OR $any_clicks_left OR $any_days_left)
        do stuff
2. Is the pipe " || " an or, and, continue, or what?
It is an 'or'.
This script is from mail.php3, a part of phpads. Almost everything with the program is great but the way this statement evaluates seems to be flawed. I have inserted tons of hooks to print out the relevent variables along the way and a set of values which should seem to evaluate to true do not. So I must be misunderstanding something above. Please someone help. I have been looking at this for 2 days and although I know a lot more I am no closer to solving it.
HTH, Zak Greant Creative Director Nucleus Information Service Inc. "I am rather like a mosquito in a nudist camp: I know what I ought to do, but I don't know where to begin." - Stephen Bayne

« previous php.general (#1994) next »