RE: [PHP] Best way to sort a multidimentional array....
| From: | Ford, Mike [LSS] | Date: | Wed, 19 Feb 2003 13:02:57 +0000 |
| Subject: | RE: [PHP] Best way to sort a multidimentional array.... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-136165@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Mark Cubitt [mailto:mark.cubitt@applegate.co.uk]
> Sent: 19 February 2003 12:43
>
> I need to manipulate, the following data in a number of
> diffierent ways
>
> I'm storing the data in a multidemensional array, the
> stucture of which
> is below, and I need to sort it by "Total Time On Phone" in decending
> order, which is the first element of the 'embedded' array.
> //just filled with some descriptive default values
> $extensionsDetails = array('Total Time On Phone', 'Total Number of
> calls', 'name of person');
>
> // a hash of extention numbers and the $extensionsDetails
> array (above)
> $telData = array(
> // management
> '2000' => $extensionsDetails,
> '2001' => $extensionsDetails,
Use usort() with a callback that compares the 'Total Time On Phone'
elements. Something like:
function compTime($a, $b) {
return $a[0]==$b[0]?0:($a[0]>$b[0]?1:-1);
}
usort($telData, 'compTime');
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211