Here’s another way of doing using the in_array function:
[php]<?php
$zone1 = [55005, 55011, 55014, 55070, 55421]; // For Service Centers 1, 5, 12
$zone2 = [55315, 55316, 55317, 55320]; // For Service Centers 3, 8, 13
/* You can have the different ‘zones’ match the $sevice_center array */
$service_center[‘zone1’][1] = “Jimmy’s Garage”;
$service_center[‘zone1’][5] = “Bob’s All-Star Garage”;
$service_center[‘zone1’][12] = “Fillmore’s Classic Garage”;
$service_center[‘zone2’][3] = “Lisa’s Hot Rods Garage”;
$service_center[‘zone2’][8] = “Mikey Does It All Garage”;
$service_center[‘zone2’][13] = “John’s Service Center”;
/* The structure of the $service_center array */
echo “
” . print_r($service_center, 1) . “
\n”;
/* Would pull in from a HTML Form */
$zip_code = filter_input(INPUT_POST, ‘zipcode’, FILTER_SANITIZE_NUMBER_INT);
/* Can use if statements or the switch statement /
if (isset($zip_code) && in_array($zip_code, $zone1)) {
/ Zone 1 Service Centers /
echo “We have found " . count($service_center[‘zone1’]) . " service centers that are near you!
\n”;
foreach($service_center[‘zone1’] as $value) {
echo $value . “
\n”;
}
} elseif (isset($zip_code) && in_array($zip_code, $zone2)) {
/ Zone 2 Service Centers /
echo “We have found " . count($service_center[‘zone2’]) . " service centers that are near you!
\n”;
foreach($service_center[‘zone2’] as $value) {
echo $value . “
\n”;
}
} elseif (isset ($zip_code)) {
/ Outside of Service Area */
echo “
We are sorry, but we found 0 service centers that are near you.
\n”;
}[/php]
Though like stated if you start having a ton of data, it probably would be best to use a database table.