KANiS Posted August 14, 2008 Share Posted August 14, 2008 Hello. I am new at php, but it is a very interesting language, so I'm learning it. So far it was going well. But now, I cant figure out one thing: I have info stored in .ini files. In that files there are names, and points gained on my site. I can read the .ini, get the name and score, but. How do I make a top 10 of users? Could anyone give me an example, because yet, I have no idea how to do this. The function I use to read .ini's: function readsave($file,$item) { $source = file($file); foreach ($source as $temp) { if (preg_match("/^".$item."=/i",$temp)) { $result = explode("=",$temp); if(!$result[1]) $result[1] = "--"; return $result[1]; } } } If anyone could help me, I would be very thankful. Link to comment https://forums.phpfreaks.com/topic/119750-easy-question/ Share on other sites More sharing options...
Barand Posted August 14, 2008 Share Posted August 14, 2008 Have you looked at parse_ini_file(), sort(), rsort() Link to comment https://forums.phpfreaks.com/topic/119750-easy-question/#findComment-616970 Share on other sites More sharing options...
akitchin Posted August 14, 2008 Share Posted August 14, 2008 you can fill up an array with the names/scores, and then sort the array: function readsave($file,$item) { $source = file($file); $scores = array(); foreach ($source as $temp) { if (preg_match("/^".$item."=/i",$temp)) { $result = explode("=",$temp); if(!$result[1]) $result[1] = 0; $scores["$result[0]"] = $result[1]; } } return $scores; } readsave() will return an array of the format name => score. use arsort() with what i would assume is SORT_NUMERIC, and there you are. EDITED BY akitchin: barand has beaten me to it, and with more handy solutions i believe. Link to comment https://forums.phpfreaks.com/topic/119750-easy-question/#findComment-616972 Share on other sites More sharing options...
KANiS Posted August 14, 2008 Author Share Posted August 14, 2008 Thanks... really. I will try to do that. Link to comment https://forums.phpfreaks.com/topic/119750-easy-question/#findComment-616974 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.