NYCPHP Meetup

NYPHP.org

[nycphp-talk] sorting multi-dimesional arrays ...

crisscott at netzero.com crisscott at netzero.com
Tue Jul 22 10:41:24 EDT 2003


I haven't had to do any complex sorting on the second element but when I do I use usort().  Something like this...

usort(two_d_array, 'second_element_sort');

function second_element_sort($a, $b) {
   if($a[0] == $b[0]) return 0;
   return ($a[0] > $b[0]) ? -1 : 1;
}

The arguments passed to second_element_sort are two_d_array[n] and two_d_array[n+1].  



More information about the talk mailing list