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: