これは、郵便番号を入力として取り、正しい配列で郵便番号を見つけて、対応する都市を返す単純な関数です。
function zipcode_search($a){
$zip = (int)$a;
//arrays of zipcodes to corresponding cities
$FtMyers = array(33901,33902,33903,33905,33906,33907,33908,33911,33912,33913,33916,33917,33918,33919,33965,33966,33967,33990,33993,33994);
$Naples = array(34101,34102,34103,34104,34105,34106,34107,34108,34109,34110,34112,34113,34114,34116,34117,34119,34120);
$Cape = array(33904,33909,33910,33914,33915,33990,33991,33993);
$PtChar = array(33948,33949,33952,33953,33954,33980,33981,33983);
$Bonita = array(34133,34134,34135,34136);
$Marco = array(34145,34146);
$Estero = array(33928,33929);
$FMBeach = array(33931,33932);
$Sanibel = array(33957);
if (in_array($zip, $Naples))
{
return "Naples, FL";
}
elseif (in_array($zip, $Marco))
{
return "Marco Island, FL";
}
elseif (in_array($zip, $Bonita))
{
return "Bonita Springs, FL";
}
elseif (in_array($zip, $Estero))
{
return "Estero, FL";
}
elseif (in_array($zip, $FtMyers))
{
return "Fort Myers, FL";
}
elseif (in_array($zip, $FMBeach))
{
return "Ft. Myers Beach, FL";
}
elseif (in_array($zip, $Cape))
{
return "Cape Coral, FL";
}
elseif (in_array($zip, $Sanibel))
{
return "Sanibel Island, FL";
}
elseif (in_array($zip, $PtChar))
{
return "Port Charlotte, FL";
}
else { return "Florida";}
}
私はこれを改善し、同時にその有効性を改善できることを知っています.