Tips & Tricks: generator 0 / 1 with the ternary operator

Who is the programming C / C + + can not know the ternary operator, ECMA, and then used in PHP, Javascript and ActionScript. Hence a simpatca "line of code" (in this case PHP) useful, for example, to generate alternate rows in an HTML table, for example, but significant for many other applications:

1
= $t == 0 ) ? "even" : "odd" ) (($ T = $ t == 0)? "Even" "odd")

I remember seeing the first time this "magic" code on a Commodore 64 (year 1984) proposed by Compute! Gazette - Basic course in the form ;)

cg.jpg

There are no comments for this post

Leave a comment

XHTML TAG PERMIT: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL