Mailinglisten-Archive |
Nora Etukudo wrote: > > On Fri, Aug 27, 1999 at 05:14:45PM +0100, Peter Muessig-Trapp wrote: > > > vor allem die 3. Zeile ... ?0:1 ... ist mir voellig raetselhaft. > > Alter C-Programmiererinnen-Trick: Ein bedingter Ausdruck. > > <bedingung> ? <ausdruck1> : <ausdruck2> Das ist aber eher dazu gedacht die Großmutter zu ... ------------------------------------------------------------ What is a ternary expression? What is this ? : syntax? ------------------------------------------------------------ Rasmus Lerdorf <rasmus_(at)_lerdorf.on.ca> Chad <ccunning_(at)_math.ohio-state.edu> Egon Schmid <eschmid_(at)_stuttgart.netsurf.de> A ternary expression is a shortened form of an if statement: ( (condition) ? "true" : "false" ) If the condition is true, then the above line evaluates to "true" and if the condition is false, it evaluates to "false". Another way to look at it. Take this very normal example: if ($a==1) { print "a is one"; } else { print "a is not one"; } Even your grandmother could probably tell you what this did. You can rewrite this with a conditional to confuse your grandmother, like this: print ( ($a==1) ? "a is one" : "a is not one" ); http://www.php.net/manual/expressions.php3 ------------------------------------------------------------- So steht's jedenfalls in der Knowledge-Datenbank. -Egon
php::bar PHP Wiki - Listenarchive