note 96685 added to control-structures.switch

From: Date: Thu, 11 Mar 2010 14:38:46 +0000
Subject: note 96685 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-166914@lists.php.net to get a copy of this message
To get switch to check the key of an array, rather than the value, you can use a foreach loop <?php #Returned $_POST #Array([option1]=>'A',[option2]=>'C',[submit]=>'Submit') foreach ($_POST as $postKey => $postValue) { switch($postKey){ case 'option1': echo"option1<br />"; break; case 'option2': echo"option2<br />"; break; default: echo"not interested<br />"; break; } } /* OUTPUT option1 option2 not interested */ ?> ---- Server IP: 78.110.173.36 Probable Submitter: 139.166.242.91 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- https://master.php.net/note/edit/96685 Del: integrated -- https://master.php.net/note/delete/96685/integrated Del: useless -- https://master.php.net/note/delete/96685/useless Del: bad code -- https://master.php.net/note/delete/96685/bad+code Del: spam -- https://master.php.net/note/delete/96685/spam Del: non-english -- https://master.php.net/note/delete/96685/non-english Del: in docs -- https://master.php.net/note/delete/96685/in+docs Del: other reasons-- https://master.php.net/note/delete/96685 Reject -- https://master.php.net/note/reject/96685 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166914) next »