note 79015 added to control-structures.alternative-syntax

From: Date: Wed, 07 Nov 2007 05:44:10 +0000
Subject: note 79015 added to control-structures.alternative-syntax
Groups: php.notes 
Request: Send a blank email to php-notes+get-132068@lists.php.net to get a copy of this message
<?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 */ ?> ---- Server IP: 69.147.83.197 Probable Submitter: 208.79.60.30 ---- Manual Page -- http://www.php.net/manual/en/control-structures.alternative-syntax.php Edit -- https://master.php.net/note/edit/79015 Del: integrated -- https://master.php.net/note/delete/79015/integrated Del: useless -- https://master.php.net/note/delete/79015/useless Del: bad code -- https://master.php.net/note/delete/79015/bad+code Del: spam -- https://master.php.net/note/delete/79015/spam Del: non-english -- https://master.php.net/note/delete/79015/non-english Del: in docs -- https://master.php.net/note/delete/79015/in+docs Del: other reasons-- https://master.php.net/note/delete/79015 Reject -- https://master.php.net/note/reject/79015 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132068) next »