note 79019 added to control-structures.alternative-syntax

From: Date: Wed, 07 Nov 2007 12:10:08 +0000
Subject: note 79019 added to control-structures.alternative-syntax
Groups: php.notes 
Request: Send a blank email to php-notes+get-132075@lists.php.net to get a copy of this message
<?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 "$var\n<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-structures.alternative-syntax.php Edit -- https://master.php.net/note/edit/79019 Del: integrated -- https://master.php.net/note/delete/79019/integrated Del: useless -- https://master.php.net/note/delete/79019/useless Del: bad code -- https://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 -- https://master.php.net/note/delete/79019/in+docs Del: other reasons-- https://master.php.net/note/delete/79019 Reject -- https://master.php.net/note/reject/79019 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132075) next »