Jump to content

Find first place, second place and so on from an associative array.


davelatham

Recommended Posts

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]
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.