> -----Original Message-----
> From: Chad Day [mailto:[EMAIL PROTECTED]]
> Sent: 30 January 2003 19:29
>
> I'm struggling with array_multisort, was hoping someone could
> give me some
> help.
>
> I have a multidim array, such as:
>
> $myarray[0][FIRSTNAME] = JOE
> $myarray[1][FIRSTNAME] = TIM
> $myarray[2][FIRSTNAME] = BOB
>
> $myarray[0][LASTNAME] = SMITH
> $myarray[1][LASTNAME] = BROWN
> $myarray[2][LASTNAME] = JONES
>
> $myarray[0][EXTENSION] = 2000
> $myarray[1][EXTENSION] = 4000
> $myarray[2][EXTENSION] = 1000
>
> I was trying array_multisort($myarray[EXTENSION],
> SORT_NUMERIC, SORT_DESC),
You won't be able to use array_multisort() to do this, as your indexes are
the wrong way round. It looks to me like the only solution is using usort()
on $myarray, with a callback function that sorts on the [EXTENSION] element;
so, something like:
function compare($a, $b) {
return $a[EXTENSION]==$b[EXTENSION]?0:($a[EXTENSION]<$b[EXTENSION]?-1:1)
}
usort($myarray, "compare");
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: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php