NYCPHP Meetup

NYPHP.org

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

Jon Baer jonbaer at jonbaer.net
Tue Jul 22 12:04:46 EDT 2003


the functon array_count_values was actually what i was looking for, but in
the test below the key values are not retained ... im still trying to figure
it out ...

$a = array("Cisco","Cisco","Intel","Apple", "Apple", "Apple", "Speedstream",
"Apple");
$b = array_count_values ($a);
 print_r($b);
 rsort($b);
 print_r($b);

- jon

pgp key: http://www.jonbaer.net/jonbaer.asc
fingerprint: F438 A47E C45E 8B27 F68C 1F9B 41DB DB8B 9A0C AF47


----- Original Message ----- 
From: <crisscott at netzero.com>
To: <talk at lists.nyphp.org>
Sent: Tuesday, July 22, 2003 7:41 AM
Subject: Re: [nycphp-talk] sorting multi-dimesional arrays ...


>
> 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].
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>




More information about the talk mailing list