Jump to content

Using foreach inside switch


parka

Recommended Posts

On a form there's a list of countries for the user to choose from.

 

On the processing script, how can I check to make sure that users have indeed choosen from the list I have provided?

 

I tried the following but it gave me a "parse error, unexpected T_FOREACH, expecting T_CASE or T_DEFAULT or '}'" on the line with the foreach statement.

 

How should I code this security check?

 

$countriesArray = array("usa", "china", "russia", "mexico");
$userChoosenCountry = "holland"; // to be replaced by $_POST later

switch ($userChoosenCountry){
foreach ($countriesArray as $country){
	case $country: print "You have choosen $country";
	break;
}
default: print "You didn't choose from the list of countries";
}

Link to comment
https://forums.phpfreaks.com/topic/41739-using-foreach-inside-switch/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.