php multidim array key sort
php multidim array key sort
- Started
- Last post
- 2 Responses
- rabattski
i have this multidimensional array. every entry has 4 keys and i want to sort the array on 2 keys. so it has to sort first on key 1 and when that's done i want to sort it on another key. so basically it's a sort within a sort. tried strcmp twice but obviously that doesn't take the previous sort in account and sorts it all over again. anyone got a clue?
- Rickbass0
Maybe my brain is small, but can you give us an example?
Can't you do something like this:
// Sort the 'first level' array
$array = sort($array);// Initiate the sorted array:
$sortedarray = array();foreach($array as $key => $subarray) {
$sortedarray[$key] = sort($subarray);
}
- rabattski0
hmmm.... that could be a solution. lemme try that. cheers though.