RE: [PHP] Re: UNLESS Statement Equivalent

[email protected] ("Ford, Mike")
Newsgroups php.general
Message-ID <3158105795AAC1408619EC8BA03384A92250761C@EXC-MBX02.leedsmet.ac.uk>
> -----Original Message-----
> From: Maciek Sokolewicz [mailto:[email protected]] On Behalf Of
> Maciek Sokolewicz
> Sent: 11 March 2013 22:44
> 

> unless ( $a and $b )
> =
> if ( ! ($a and $b) )
> 
> So in simple terms, just stick a ! (or the keyword not) in front of
> your
> expression, and you'll have exactly what you want:
> if( not ( ($current_page == $saved_page) and ($current_ip ==
> $saved_ip)
> and ($current_dt < ($saved_dt + 3600) ) ) {

Whilst this is true as far as it goes, I would suggest applying deMorgan's laws
to simplify slightly to

   if ( ($current_page != $saved_page) or ($current_ip != $saved_ip) or ($current_dt >= ($saved_dt + 3600) ) )

Also, the keyword versions of the Boolean operators are very low
priority, which is why you need all those extra parentheses -- if
you switch to the symbolic versions, you can leave all the internal
parentheses out to give:

   if ($current_page != $saved_page || $current_ip != $saved_ip || $current_dt >= $saved_dt + 3600)


Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: [email protected]     T: +44 113 812 4730





To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.