I need to check whether selected city ( $_GET['city'] ) behaves in $cities array or not. Right now i'm getting errors "Undefined variable: cities" and "Invalid argument supplied for foreach()". If i check $cities with is_array it returns true. How can i fix my code?
$cities = array ("London" => "name/name2/name3",
"Paris" => "name/name3/name4",
"Moscow" => "name/name5/name6",
"Paraguay" => "name/name4/name5");
function CityIsCorrect() { //IN WORK
if (empty($_GET['city'])) {return false;}
foreach ($cities as $citycheck){
if(($_GET['city'])==$citycheck) {return true;}
else {return false;}
}
}