note 103202 added to control-structures.if

From: Date: Thu, 31 Mar 2011 14:01:56 +0000
Subject: note 103202 added to control-structures.if
Groups: php.notes 
Request: Send a blank email to php-notes+get-178376@lists.php.net to get a copy of this message
Be careful when you chain inline "if" : $x = 1; $y = 3; echo ($x==1) ? "One" : ($y == 2) ? "Two" : "None"; Expected result : "One". Result on screen : "Two". Pretty disapointing isn't it ? So, if you want to chain inline "if" you have to use parentesis on each test like below: $x=1; $y=3; echo ($x==1) ? "One" : ( ($y==2) ? "Two" : "None" ); Result on screen : "One". Hope it helps ! ---- Server IP: 69.147.83.197 Probable Submitter: 212.51.169.88 ---- Manual Page -- http://www.php.net/manual/en/control-structures.if.php Edit -- https://master.php.net/note/edit/103202 Del: integrated -- https://master.php.net/note/delete/103202/integrated Del: useless -- https://master.php.net/note/delete/103202/useless Del: bad code -- https://master.php.net/note/delete/103202/bad+code Del: spam -- https://master.php.net/note/delete/103202/spam Del: non-english -- https://master.php.net/note/delete/103202/non-english Del: in docs -- https://master.php.net/note/delete/103202/in+docs Del: other reasons-- https://master.php.net/note/delete/103202 Reject -- https://master.php.net/note/reject/103202 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178376) next »