Ich habe ein paar Arrays wie folgt.
Array
(
[state] => Array
(
[0] => WA
[1] => CA
[2] => CA
[3] => NV
[4] => MO
[5] => CA
[6] => CA
[7] => CA
[8] => CT
[9] => FL
[10] => FL
[11] => ID
[12] => ID
[13] => IN
[14] => MN
[15] => MN
[16] => NE
[17] => NY
[18] => TX
[19] => TX
[20] => WI
)
[counties] => Array
(
[0] => King, Snohomish
[1] => Contra Costa
[2] => Los Angeles
[3] => Clark
[4] => Jackson
[5] => Tulare
[6] => Sacramento
[7] => Riverside
[8] => New Haven
[9] => Pinellas
[10] => Lake
[11] => Canyon
[12] => Ada
[13] => Tippecanoe, White, Carroll
[14] => Crow Wing, Cass
[15] => Blue Earth
[16] => Douglas
[17] => Rockland
[18] => Webb
[19] => Harris
[20] => Waukesha, Milwaukee, Washington
)
[zipcodes] => Array
(
[0] => 98004, 98005, 98006, 98007, 98008, 98011, 98012, 98102, 98105, 98112, 98136, 98025, 98033, 98034, 98083
[1] => 94530, 94804, 94805, 94803, 94806, 94564, 94547
[2] => 91381, 91384, 91354, 91355, 91321, 91387, 91351, 91390, 91350
[3] => 89002, 89009, 89011, 89012, 89014, 89015, 89016, 89128, 89048, 89052, 89053, 89060, 89061, 89074, 94588, 89102, 89105, 89108, 89109, 89111, 89112
[4] => 64055, 64056, 64057, 64052, 64064, 64050, 64058, 64014, 64015, 64029, 64063, 64081, 64082, 64086, 64133
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
)
Ich versuche nach Postleitzahlen, Staaten und Counties zu sortieren. Das Problem, das ich habe, besteht darin, die Postleitzahlen in aufsteigender Reihenfolge nach der ersten Postleitzahl im String anzuzeigen. Also wäre die Reihenfolge
64055, 64056, ...
89002, 89009, ...
91381, 91384, ...
94530, 94804, ...
Hier sind meine aktuellen Ergebnisse.
WA,TL-WA-150,150,King, Snohomish,98004, 98005, 98006, 98007, 98008, 98011, 98012, 98102, 98105, 98112, 98136, 98025, 98033, 98034, 98083
CA,HD-CA-125,125,Contra Costa,94530, 94804, 94805, 94803, 94806, 94564, 94547
CA,DH-CA-125,150,Los Angeles,91381, 91384, 91354, 91355, 91321, 91387, 91351, 91390, 91350
NV,CM1-NV-150,150,Clark,89002, 89009, 89011, 89012, 89014, 89015, 89016, 89128, 89048, 89052, 89053, 89060, 89061, 89074, 94588, 89102, 89105, 89108, 89109, 89111, 89112
MO,CJ-MO-150,150,Jackson,64055, 64056, 64057, 64052, 64064, 64050, 64058, 64014, 64015, 64029, 64063, 64081, 64082, 64086, 64133
CA,GR6-CA-150,150,Tulare,
CA,SSJ-CA-150,150,Sacramento,
CA,LM1-CA-150,150,Riverside,
CT,TAMRM-CT-150,150,New Haven,
FL,GG-FL-150,150,Pinellas,
Meine Frage ist, wie kann ich die Postleitzahlen aufsteigend sortieren?
Ich verwende derzeit die folgende Funktion zum Sortieren.
sortDataSet($difarray, 'zipcodes', SORT_DESC, SORT_NUMERIC, 'state', SORT_ASC, SORT_STRING,'counties', SORT_DESC, SORT_STRING);
function sortDataSet(&$dataSet) {
$args = func_get_args();
$callString = 'array_multisort(';
$usedColumns = array();
for($i = 1, $count = count($args); $i < $count; ++$i) {
switch(gettype($args[$i])) {
case 'string':
$callString .= '$dataSet[\''.$args[$i].'\'], ';
array_push($usedColumns, $args[$i]);
break;
case 'integer':
$callString .= $args[$i].', ';
break;
default:
throw new Exception('expected string or integer, given '.gettype($args[$i]));
}
}
foreach($dataSet as $column => $array) {
if(in_array($column, $usedColumns)) continue;
$callString .= '$dataSet[\''.$column.'\'], ';
}
eval(substr($callString, 0, -2).');');
}