[ create a new paste ] login | about

Link: http://codepad.org/y9Q5bpuQ    [ raw code | output | fork ]

morrison.levi - PHP, pasted on Oct 14:
<?php

$players = array(
     array(
          'name'=>'John',
          'rating'=>100
     ),
     array(
          'name'=>'admin',
          'rating'=>500
     ),
     array(
          'name'=>'james',
          'rating'=>200,
     )
);

function player_sort($a,$b) {
      return $a['rating']>$b['rating'];
}


usort($players, "player_sort");


for($i=0, $j=count($players)-1; $i<$j; $i++, $j--) {
     echo 'High: '.$players[$i]['name'];
     echo 'Low: '.$players[$j]['name'];
}

?>


Output:
1
High: JohnLow: admin


Create a new paste based on this one


Comments: