RE: [PHP] shorthand "if" notation

From: Date: Wed, 11 Jun 2003 16:04:23 +0000
Subject: RE: [PHP] shorthand "if" notation
Groups: php.general 
Request: Send a blank email to php-general+get-151099@lists.php.net to get a copy of this message
> -----Original Message----- > From: adrian GREEMAN > [mailto:adriangreeman@pixandwords.freeserve.co.uk] > Sent: 11 June 2003 15:23 > > I am confused by the shorthand "if" notation. > For example I just saw this PHP snippet on another forum > > <? > $bkgndClass = $bkgndClass == "darkBkgnd" ? "liteBkgnd" : > "darkBkgnd"; > } > ?> > > I think it is an if but cannot find it in the manual. How > is that written in the more normal notation - if(){} etc?? See http://uk.php.net/manual/en/language.operators.comparison.php where the ?: operator is explained. > [And please excuse a slightly off-thread but related extension to > the question but I have seen similar in Javascript - namely --- > var evt = (evt ? evt : ((window.event) ? window.event : null); > is this the same notation or something else?] Yes, same basic notation -- the only minor difference is that the associativity is different, so nested ?: operators are evaluated in a different order. Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#151099) next »