Ternary Operator

Posted by Trey on September 20, 2006

Like this:

<?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'];
}

?>

This kind of thing works in all “C-like” languages right? (JavaScript, PHP, etc.)

More info.

If/Then/Else statments are a type of Control Structure: Wikipedia, PHP docs.