Jump to content


Photo

**solved** Sorting by key ?


  • Please log in to reply
2 replies to this topic

#1 acey99

acey99
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 18 April 2006 - 08:18 PM

ok say I have the following:


$StandingsData[$i]['teamid']
$StandingsData[$i]['gamesplayed']
$StandingsData[$i]['points']


& want to sort this by say points, how do I do that ?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 18 April 2006 - 10:08 PM


function points_sort ($a, $b) {

          if ($a['points'] == $b['points']) return 0;
          return ($a['points'] < $b['points']) ? -1 : 1;
}


usort ($StandingsData, 'points_sort');


// check results

echo '<pre>', print_r ($StandingsData, true), '</pre>';

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 acey99

acey99
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 18 April 2006 - 11:14 PM

Thanks !




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users