Given this script:
<?php
$file = file('info.txt');
$statelist = array (1=> "California", "Florida", "Illinois", "New York", "Texas");
foreach ($file as $line => $data)
{
list($state, $abbrev, $population) = explode('|', trim($data));
for ($x=1; $x<5; $x++) {
if ($statelist[$x] == $state) {
echo $state . ", " . $abbrev . " - " . $population . '<br />';
}
}
}
?>
and this flat file (info.txt):
California|CA|36,756,666
Texas|TX|24,326,974
New York|NY|19,490,297
Florida|FL|18,328,340
Illinois|IL|12,901,563
This is what is outputted:
California, CA - 36,756,666
Texas, TX - 24,326,974
New York, NY - 19,490,297
Florida, FL - 18,328,340
Illinois, IL - 12,901,563
How can I sort the output by the index value of the "statelist array" so get this output:
California, CA - 36,756,666
Florida, FL - 18,328,340
Illinois, IL - 12,901,563
New York, NY - 19,490,297
Texas, TX - 24,326,974
Could ksort($statelist) be implemented?