Problem: I have an associative multi-dimensional array with each key having an array inside. It looks like this:
array(3){
[1]=>
"id"=>1
"name"=>"Test #1"
"listorder"=>1
[6]=>
"id"=>6
"name"=>"Test #1"
"listorder"=>3
[2]=>
"id"=>2
"name"=>"Test #2"
"listorder"=>2
}
I need to sort this array by each array's listorder
value without changing any of the key numbers. How can this be done?
I am currently trying this code which I got from a separate Stack overflow question.
function sort_array(){
foreach($array as $key => $row){
$listorder[$row["id"]] = $row["listorder"];
}
array_multisort($listorder, SORT_ASC, $array);
return $array;
}
But this specific code rewrites all of the key numbers. Is there another way to sort without changing anything?