Re: [4.3.4] Can't ksort a subarray
| From: | DvDmanDT | Date: | Thu, 25 Mar 2004 23:25:39 +0000 |
| Subject: | Re: [4.3.4] Can't ksort a subarray | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-181520@lists.php.net to get a copy of this message | ||
I'd do this I think:
uksort($A,'strcasecmp');
reset($A);
while(list($key,$val)=each($A))
{
uksort($A[$key],'strcasecmp');
}
--
// DvDmanDT
MSN: dvdmandt¤hotmail.com
Mail: dvdmandt¤telia.com
"Richard A. Devenezia" <radevenz@ix.netcom.com> skrev i meddelandet
news:20040325163258.92030.qmail@pb1.pair.com...
> I have this little code.
> I want all arrays sorted case insensitive key order, but only the first
> dimension gets key sorted properly
>
> Thanks
> --
> Richard A. DeVenezia
>
> <?
>
> $A = array (
> "C" => array ( "x" => 1, "Z" => 2, "y" =>
3)
> , "b" => array ( "z" => 1, "Y" => 2, "x" =>
3)
> , "A" => array ( "z" => 1, "X" => 2)
> );
> print_r ($A);
>
> // sort dim1
> uksort ($A, "strcasecmp");
> print_r ($A);
>
> // sort each dim2
> while (list($key,$dim2) = each ($A)) {
> uksort ($dim2, "strcasecmp");
> }
> print_r ($A);
>
> ?>
>
> It comes out
>
> Array
> (
> [A] => Array
> (
> [z] => 1
> [X] => 2
> )
>
> [b] => Array
> (
> [z] => 1
> [Y] => 2
> [x] => 3
> )
>
> [C] => Array
> (
> [x] => 1
> [Z] => 2
> [y] => 3
> )
> )
>
> I want
>
> Array
> (
> [A] => Array
> (
> [X] => 2
> [z] => 1
> )
>
> [b] => Array
> (
> [x] => 3
> [Y] => 2
> [z] => 1
> )
>
> [C] => Array
> (
> [x] => 1
> [y] => 3
> [Z] => 2
> )
> )