Cobalt.Board Posted July 21, 2009 Share Posted July 21, 2009 Hey, I need help! I have the following bit of code: $delimiter="\t"; $lines=file($settings['logfile']); list($name,$from,$email,$url,$comment,$added,$isprivate,$reply)=explode($delimiter,$lines[$num]); I need to sort that list numerically by the $comment variable. How do I do this? Link to comment https://forums.phpfreaks.com/topic/166719-sorting-a-list/ Share on other sites More sharing options...
MadTechie Posted July 21, 2009 Share Posted July 21, 2009 try this <?php $delimiter="\t"; $lines=file($settings['logfile']); foreach($lines as $K => $line) { $lines[$K] = explode($delimiter,$line); } usort($lines, "cmp"); foreach($lines as $K => $line) { list($name,$from,$email,$url,$comment,$added,$isprivate,$reply)= $line; echo "$name,$from,$email,$url,$comment,$added,$isprivate,$reply\n"; } function cmp($a, $b) { return strcmp($a[4], $b[4]); } ?> Link to comment https://forums.phpfreaks.com/topic/166719-sorting-a-list/#findComment-879178 Share on other sites More sharing options...
Cobalt.Board Posted July 21, 2009 Author Share Posted July 21, 2009 No luck. I spill sorts the old way. The comments are just numbers, and I need it to sort them with the highest first. Link to comment https://forums.phpfreaks.com/topic/166719-sorting-a-list/#findComment-879261 Share on other sites More sharing options...
Cobalt.Board Posted July 21, 2009 Author Share Posted July 21, 2009 Can anybody help? Link to comment https://forums.phpfreaks.com/topic/166719-sorting-a-list/#findComment-879543 Share on other sites More sharing options...
MadTechie Posted July 21, 2009 Share Posted July 21, 2009 humm can you post an example file Link to comment https://forums.phpfreaks.com/topic/166719-sorting-a-list/#findComment-879743 Share on other sites More sharing options...
Cobalt.Board Posted July 21, 2009 Author Share Posted July 21, 2009 What do you mean example file? I'm using an open-source guestbook script and modding it into a highscores script. Link to comment https://forums.phpfreaks.com/topic/166719-sorting-a-list/#findComment-879850 Share on other sites More sharing options...
MadTechie Posted July 22, 2009 Share Posted July 22, 2009 and can you send the file that your reading from, the file set here $settings['logfile'] Link to comment https://forums.phpfreaks.com/topic/166719-sorting-a-list/#findComment-880208 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.