FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Array_multisort help please
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Array_multisort help please [message #170285 is a reply to message #170284] Tue, 26 October 2010 18:20 Go to previous messageGo to previous message
MikeB is currently offline  MikeB
Messages: 65
Registered: September 2010
Karma:
Member
Denis McMahon wrote:

>
> If you replace the line:
>
> array_multisort($array1,SORT_REGULAR);
>
> with the following:
>
> // starts here
> ksort($array1);
> foreach ($array1 as $key => $value) {
> ksort($value);
> $array1[$key] = $value;
> }
> // ends here
>
> Do you get the result you want?
>

Dennis, thank you, it does indeed.

I had to spend quite some time to try and figure out what your code was
doing, so if you don't mind, can you please check my comments and tell
me if I figured it out correctly?

> ksort($array1);

Sort the outer (high-level index of the array

> foreach ($array1 as $key => $value) {

iterate through each of the high-level indexes of the array, with
"$value" being a new array containing the sub-array that was in that key.

> ksort($value);

sort the sub-array

> $array1[$key] = $value;

replace the previous sub-array in $array1 with the new, sorted sub-array.

> }


So
essentially there isn't an in-place sort that would have done what I
wanted to do and this is a slick method to simulate that?

MikeB
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: IT job
Next Topic: Php windows system(whois) not working
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 22:22:37 GMT 2024

Total time taken to generate the page: 0.03828 seconds