Order a foreach, by the value of a calculation of values in the array

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2012-09-03T15:22:13Z Indexed on 2012/09/03 15:38 UTC
Read the original article Hit count: 138

Filed under:

I have an array as follows:

$players = array(
    $player = array(
        'name'          => 'playername',
        'speed'         => '10',
        'agility'       => '10',
        'influence'     => '10'
    )
    etc

Then I calculate a $score, based on the sum of speed, agility and influence.

$score = $p['speed'] + $p['agility'] + $p['influence'];

How can I loop through my array, but order the results from highest to lowest $score?

PS-> http://pastebin.com/eUEQ5y4u

© Stack Overflow or respective owner

Related posts about php