<?php
/*
TENARY OPERATOR : ALTERNATIVE SYNTAX
Expression - 1 (True or False) ? Expression - 2 (True) :
Expression -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 = "Value is One";
}
else if($a == 24)
{
$var = "24th Avenue";
}
else
{
$var = "Not equal to One nor 24";
}
*/
$var = $a == 1 ? "Value is One" : ($a == 24 ?
"24th Avenue" : "Not equal to One nor
24");
echo "$varn<br>";
/*
Which generates following output as $a = 24
24th Avenue
More information on tenary expression can be found on
following links:
http://www.phpvalue.com/what-is-php-ternary-opeartor/
http://www.rasyid.net/2006/11/20/php-ternary-operator/
*/
?>
----
Server IP: 69.147.83.197
Probable Submitter: 208.72.122.137
----
Manual Page -- http://www.php.net/manual/en/control-struc
tures.alternative-syntax.php
Edit -- https://master
.php.net/note/edit/79019
Del: integrated -- h
ttps://master.php.net/note/delete/79019/integrated
Del: useless -- http
s://master.php.net/note/delete/79019/useless
Del: bad code -- htt
ps://master.php.net/note/delete/79019/bad+code
Del: spam -- https:/
/master.php.net/note/delete/79019/spam
Del: non-english --
https://master.php.net/note/delete/79019/non-english
Del: in docs -- http
s://master.php.net/note/delete/79019/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/79019
Reject -- https://mast
er.php.net/note/reject/79019
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|