davelatham Posted January 18, 2007 Share Posted January 18, 2007 I am working on a sweepstakes project where users make picks for the Rugby Super14 competition. They score points based on the accuracy of their picks. I am able to generate an array of data that looks similar to this:[code]$rounds = array(1 => array( "userName1" => 12, //Score for round 1 for userName1 "userName2" => 7, "userName3" => 12),2 => array( "userName1" => 9, //Score for round 2 for userName1 "userName2" => 16, "userName3" => 10));[/code]You get the picture.What I need to do is find, for each round, who came first, second and last based on the users scores for that round.If anyone could point me in the right direction, I would REALLY appreciate it.Dave Latham[url=http://code.google.com/p/s14]http://code.google.com/p/s14[/url] Link to comment https://forums.phpfreaks.com/topic/34661-find-first-place-second-place-and-so-on-from-an-associative-array/ Share on other sites More sharing options...
davelatham Posted January 18, 2007 Author Share Posted January 18, 2007 I would also like to point out that more than one person may score the same winning score on a round. This would mean, under the "business logic" there would be joint winners or joint place holders who would share the prize money.The issue really is that a simple array_sort and then selecting the $array[0] index and $array[1] index for the winner and runner up wont always work.Dave Latham[quote author=davelatham link=topic=122903.msg507459#msg507459 date=1169082935]I am working on a sweepstakes project where users make picks for the Rugby Super14 competition. They score points based on the accuracy of their picks. I am able to generate an array of data that looks similar to this:[code]$rounds = array(1 => array( "userName1" => 12, //Score for round 1 for userName1 "userName2" => 7, "userName3" => 12),2 => array( "userName1" => 9, //Score for round 2 for userName1 "userName2" => 16, "userName3" => 10));[/code]You get the picture.What I need to do is find, for each round, who came first, second and last based on the users scores for that round.If anyone could point me in the right direction, I would REALLY appreciate it.Dave Latham[url=http://code.google.com/p/s14]http://code.google.com/p/s14[/url][/quote] Link to comment https://forums.phpfreaks.com/topic/34661-find-first-place-second-place-and-so-on-from-an-associative-array/#findComment-163359 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.