9999 Posted September 29, 2010 Share Posted September 29, 2010 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? Link to comment https://forums.phpfreaks.com/topic/214780-sorting-output-from-flat-file-db/ Share on other sites More sharing options...
litebearer Posted September 29, 2010 Share Posted September 29, 2010 If you use the flatfile db much - you might look into http://lukeplant.me.uk/resources/flatfile/ Link to comment https://forums.phpfreaks.com/topic/214780-sorting-output-from-flat-file-db/#findComment-1117394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.