note 79015 deleted from control-structures.alternative-syntax by tularis
| From: | tularis@php.net | Date: | Wed, 07 Nov 2007 08:55:20 +0000 |
| Subject: | note 79015 deleted from control-structures.alternative-syntax by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-132072@lists.php.net to get a copy of this message | ||
Note Submitter: SID TRIVEDI
Reason: useless
----
<?php
/*
TENARY OPERATOR : ALTERNATIVE SYNTAX
Expr-1 (True or False) ? Expr-2 (True) : Expr-3 (False);
Condition to be evaluated or Boolean Expression to be evaluated True or False ?
Codes to be excuted , if true :
codes to be executed, if false;
The following codes can be replaced by following tenary expression as shown:
*/
$a=24;
/* // Codes replacement by tenary expression.
if($a == 1)
{
$var = "One";
}
else if($a == 24)
{
$var = "Twenty Four";
}
else
{
$var = "Not One nor Twenty Four";
}
*/
$var=$a==1? "One" :($a==24? "Twenty Four":"Not One nor Twenty Four");
echo "$var\n<br>";
/*
Which generates following output as $a = 24
Twenty Four
*/
?>