Array multisort problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Marchingtune
Forum Newbie
Posts: 2
Joined: Sat Oct 24, 2009 11:27 pm

Array multisort problem

Post by Marchingtune »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Please help, trying to sort the below arrays based on the third element then the second element. Instead this code sorts based on element 1 which in this test example i don't care about.

Code: Select all

<?php
$test[]=array(1,2,3);
$test[]=array(1,1,6);
$test[]=array(1,1,5);
$test[]=array(2,1,2);
$test[]=array(2,1,1);
 
foreach($test as $value)
{
    $aTemp1[]=$value;
    $aTemp2[]=$value;
    $aTemp3[]=$value;
}
 
array_multisort($aTemp3,SORT_ASC, $aTemp2, SORT_ASC,$test);

print_r($test);
?>

This code returns the below

Array ( [0] => Array ( [0] => 1 [1] => 1 [2] => 5 ) [1] => Array ( [0] => 1 [1] => 1 [2] => 6 ) [2] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [3] => Array ( [0] => 2 [1] => 1 [2] => 1 ) [4] => Array ( [0] => 2 [1] => 1 [2] => 2 ) )


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
Marchingtune
Forum Newbie
Posts: 2
Joined: Sat Oct 24, 2009 11:27 pm

Re: Array multisort problem

Post by Marchingtune »

Thank you works great.
Post Reply