
March 3rd, 2004, 01:43 PM
|
|
Registered User
|
|
Join Date: Apr 2007
Posts: 22,309
Time spent in forums: < 1 sec
Reputation Power: 25
|
|
|
sorting on multidimensional arrays
Hi there, I have a multidimensional array that I would like to sort.
I have 10 people who are playing a game. I know all their scores
ie Aaron = 9, Bill = 6, Charles= 9, David = 4, Evan = 8, Fred = 2, Greg = 7, Hamish = 2, Ian = 8, John = 3
The players are currently structured as such:
$players = array("aaron" => array("david", "evan", "greg" =>array("hamish", "ian")), "bill" => array("charles" => array("fred", "john")))
I would like to sort them so that the players with high scores are promoted up the chain (ie in this example Charles(9) is promoted over Bill(6) and Ian(8) gets promoted over Greg(7).
I presume that this is possible, but I'm not sure how to implement this. I've looked into the various array sorting options, but they all seem to do their comparisons on the heirachy level, rather than down a chain/branch.
I also tried recursing through the array, and attempted to reference the array dynamically with variable substitution but ran up against some brick walls. I tried to do something like the following to no avail.
$x = "[aaron][greg]";
print_r( $players"{$x}" );
TIA
stuart
|