06-06-2005, 10:10 PM
|
#5 (permalink)
|
|
The Acquainted
Join Date: May 2005
Posts: 106
Thanks: 0
|
Ternary Operator
This is great operator. its actually an if-else statement, but they gave it a fancy name.
the syntax is
(condition)?this:else;
it says if the condition is TRUE then do this or do else
example:
PHP Code:
$flag = TRUE;
$msg = ($flag)?'Hired':'Fired';
The examples says, if flag is true then store 'Hired' in $msg else store 'Fired'.
The more general example is using different colors for rows
PHP Code:
$color = '203030';
$flag = TRUE;
echo '<table>';
while($flag)
{
echo '<tr bgcolor="'.(($color=='203030')?'404040':'203030').'"><td> Row with different color</td></tr>';
}
echo '</table>';
Hope this was helpful
__________________
---------------------------
Errors = Improved Programming.
Portfolio
|
|
|