php - Sorting 2 arrays to get the highest in one and lowest in another -


i have 2 arrays. keys represent player id in game (and same in both arrays) , value represents ping in 1 , score in other. trying player id (key) has highest ping , lowest score. can't head around of sorts this.

i don't have use 2 arrays, don't know how else it.

thanks.

live demo: http://codepad.org/46m3mhih

arranging type of architecture work better...

$players = array(     array(         "name" => "l337 h4x0r",         "score" => 10432,         "ping" => 0.35     ),     array(         "name" => "el kabooom",         "score" => 19918,         "ping" => 0.45     ),     array(         "name" => "kapop",         "score" => 10432,         "ping" => 0.38     ) ); 

then more efficiently sort multi-dimensional array, , retrieve $lowestscore , $highestping values.

$playersscore = subval_sort($players,'score');  $lowestscore = $playersscore[0]['score'];  $playersping = subval_sort($players,'ping');  $highestping = $playersping[ count($players)-1 ]['score'];  function subval_sort($a,$subkey) {     foreach($a $k=>$v) {         $b[$k] = strtolower($v[$subkey]);     }     asort($b);     foreach($b $key=>$val){         $c[] = $a[$key];     }     return $c; } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -