note 93843 added to control-structures.switch

From: Date: Fri, 02 Oct 2009 19:00:43 +0000
Subject: note 93843 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-161237@lists.php.net to get a copy of this message
Note: the suggestion from August 24, 2009 ("you can also use operators in each case statement") is incorrect. If you use an operator as in the example given, the program flow will ALWAYS go through that case statement ("Do something here"), no matter what the value of $Mode is. Not very useful. To use an operator you'll need to specify a complete condition as in the second case statement below: <?php switch($Mode) { case "one": // First mode break; case ($Mode == "open" || $Mode == "view"): // Do open or view break; default: echo 'Invalid mode'; break; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 76.241.137.2 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- https://master.php.net/note/edit/93843 Del: integrated -- https://master.php.net/note/delete/93843/integrated Del: useless -- https://master.php.net/note/delete/93843/useless Del: bad code -- https://master.php.net/note/delete/93843/bad+code Del: spam -- https://master.php.net/note/delete/93843/spam Del: non-english -- https://master.php.net/note/delete/93843/non-english Del: in docs -- https://master.php.net/note/delete/93843/in+docs Del: other reasons-- https://master.php.net/note/delete/93843 Reject -- https://master.php.net/note/reject/93843 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161237) next »