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 #170284 is a reply to message #170282] Tue, 26 October 2010 17:33 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On 26/10/10 16:45, MikeB wrote:
> I'm having a problem with using the array_multisort() function.
>
> One key is a string consisting entirely of numbers and the function
> reads that as an index and reindexes the array, thus destroying the
> actual values.
>
> What I'm trying to achieve is to make sure that the second dimension is
> always consistently sorted alphabetically. Eg. The key "siccles" should
> always precede the key "UpperKEES' when both are present.
>
> Thanks,
> MikeB
>
> This is what I have:
>
> <?php
> $array1 = array(
> "10453"=> array(
> "UpperKEES"=> array(
> "ts"=>"1,2,3",
> "score"=>"9854")
> )
> );
> $array1["10453"]["siccles"] = array("ts"=>"4,5,6","score"=>"9854");
> $array1["20095"]["siccles"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["32095"]["siccles"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["32095"]["UpperKEES"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["45695"]["UpperKEES"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["45695"]["siccles"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["53216"]["siccles"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["53216"]["UpperKEES"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["66595"]["UpperKEES"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["75489"]["UpperKEES"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["89654"]["UpperKEES"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["89654"]["siccles"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["99095"]["siccles"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["99095"]["UpperKEES"] = array("ts"=>"3,5,4","score"=>"4751");
> $array1["99995"]["siccles"] = array("ts"=>"3,5,4","score"=>"4751");
>
> array_multisort($array1,SORT_REGULAR);
>
> echo "<h2>Array 1 sorted var_dump</h2><br /><pre>";
> var_dump($array1);
> echo "</pre>";
> ?>

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?

Rgds

Denis McMahon
[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: Wed Nov 27 00:41:22 GMT 2024

Total time taken to generate the page: 0.03817 seconds