Re: Does this If statement make sense?

From: Date: Tue, 21 Feb 2006 21:40:03 +0000
Subject: Re: Does this If statement make sense?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-230842@lists.php.net to get a copy of this message
On Tue, February 21, 2006 9:55 am, Jeff wrote: > I'm again working with someone else's code and I have a problem I > believe is in the section below. The problem is, I can't seem to > understand what the "IF" conditions are saying here. The problem I > have > is with the second condition. To me this reads in psudo code: > > If( X and (if Y exists, then W otherwise Z)) > > Does this work? If so how is it evaluated? > > Here is the actual code. > <code> > > if ($tostaf && ($reply->comment ? $config->send_comment_staf : > $config->send_emailreply_staf)) Makes sense to me... If $tostaf is false, the rest of this stuff is irrelevant, and the whole block can be ignored. If $tostaf is TRUE, then check $reply->comment. If $reply->comment is TRUE, check $config->send_comment_staf If $reply->comment is FALSE, check $config->send_emailreply_staf The $config->send_XYZ is going to ALSO be evaluated as TRUE/FALSE, whichever one of the two setting is relevent. It might be more clear to write it like this: $config_send = $reply->comment ? $config->send_comment_staf : $config->send_emailreply_staf; if ($tostaf && $config_send){ $to = array(); ... } -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#230842) next »