|
Web Contractors Web Developer Jobs Join Us / Log in Discussion |
If else shortcut.
Submitted by rimian on Mon, 01/08/2007 - 07:05
I always forget this and then I have to search for it on google. So I'm putting it here where I can remember.
The Javascript if else shortcut goes like this:
Expression?true part:false part
For example:
(actor=="kevin bacon") ? alert("My favourite Actor") : alert("who?");
The PHP if else shortcut is similar:
(myexpression) ? //do the true thing : //the false part;
For Example:
$failure = ($president == 'George W. Bush') ? 1 : 0;
The Alternative Syntax for PHP is here:
http://www.php.net/manual/en/control-structures.alternative-syntax.php
There's a good advanced Javascript tutorial here:
http://www.webmonkey.com/webmonkey/98/29/index0a.html?tw=programming
New forum topics
- Freelance Web developer wanted
- Ringtone fatigue
- web developer looking for more project
- PHP website maintenance
- Desk available for hire - Rushcutters Bay location
- ZAMP?
- Don't hack the Drupal Core. Make a patch!
- What to charge for site updates
- Start New Website or CMS business. Business Partner / designer
- Code snippets in Google Search Results
- [syd] Freelance developer - .NET/ PHP/ Actionsctipt / DHTML
- Tester needed
- Freelance SharePoint 2003 / 2007 Consultant
- Joomla and Community Builder Module
- PHP export to CSV


Post new comment