sorting multi-dimensional arrays
| From: | Phil Ewington - 43 Plc | Date: | Mon, 22 Dec 2003 14:08:06 +0000 |
| Subject: | sorting multi-dimensional arrays | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-173148@lists.php.net to get a copy of this message | ||
Hi All,
I am trying to sort a multi-dimensional array using a value in the second
dimension. I have looked at the usort examples but don't fully understand
what usort is actually doing so am struggling. I have tried the following:
if (! getmxrr($this->_Domain, $as_hosts, $ai_weights))
{
return false;
}
for ($i = 0; $i < count($as_hosts); $i++)
{
$this->MXRecs[] = array($as_hosts[$i], $ai_weights[$i]);
}
function IsBestMX($a, $b)
{
if ($a[1] == $b[1])
{
return 0;
}
return ($a[1] < $b[1]) ? -1 : 1;
}
usort($this->MXRecs);
Can anyone point me in the right direction?
TIA
Phil.
---
Phil Ewington - Technical Director
43 Plc - Ashdale House
35 Broad Street, Wokingham
Berkshire RG40 1AU
T: +44 (0)1189 789 500
F: +44 (0)1189 784 994
E: mailto:phil.ewington@43plc.com
W: www.soyouthink.com