note 96685 deleted from control-structures.switch by aidan
| From: | aidan@php.net | Date: | Tue, 04 May 2010 04:02:37 +0000 |
| Subject: | note 96685 deleted from control-structures.switch by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168904@lists.php.net to get a copy of this message | ||
Note Submitter: eg1z07 at noc dot soton dot ac dot uk
----
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
*/
?>