manipulating arrays
Posted: Tue Jan 09, 2007 4:26 pm
I am attempting to rank some values in a game I am making.
So, array $attack_values is now as follows: The first element has the userid (for its value) of the user with the highest attack, the second element has the userid (for its value) of the element with the second highest attack.
I want to make a new array called $attack_ranks() mapping the userid to the element number from $attack_values that the userid occurred at.
My problem is in the while loop. I cant get the value of $attacks[$i] (which is the userid) into the array $attack_ranks(). I get an output as shown below...
Shears
Code: Select all
$attack_values = array(0 => 12, 1 => 18, 2 => 15, 3 =>16); // ie. userid 0 has an attack value of 12, userid 1 has an attack value of 18 etc...
arsort($attack_values); // rank the users
$attack_values= array_flip($attack_values);I want to make a new array called $attack_ranks() mapping the userid to the element number from $attack_values that the userid occurred at.
Code: Select all
$attack_ranks = array();
$i = 0;
while ($i < 5) {
$attack_ranks[] = $attack_values[$i];
$i++;
}
foreach($attack_ranks as $key => $value)
{
echo "$key = $value<br/>";
}Thank you for any help.0 =
1 =
2 =
3 =
4 =
Shears