View Single Post
  #24 (permalink)  
Old 04-22-2008, 02:02 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Operations in PHP

Ternary Operator

Another conditional operator is the "?:" (or ternary) operator.

PHP Code:
<?php
 
// Example usage for: Ternary Operator
 
$action = (empty($_POST['action'])) ? 'default' $_POST['action'];

 
// The above is identical to this if/else statement
 
if (empty($_POST['action'])) {
     
$action 'default';
 } else {
     
$action $_POST['action'];
 }

 
?>
The expression (expr1) ? (expr2) : (expr3) evaluates to expr2 if expr1 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE.
__________________
With,
J. Jeyaseelan

Everything Possible
Reply With Quote