I have to use a webservice which return JSON. After decode JSON I get array:
$arrays[0]["2013-04-09"]=$someValue;
$arrays[1]["2013-04-09"]=$someValue;
$arrays[2]["2013-04-11"]=$someValue;
$arrays[3]["2013-04-05"]=$someValue;
$arrays[4]["2013-04-09"]=$someValue;
I want sort (stable way and using key of second dim key) array and get as result:
$arrays[3]["2013-04-05"];
$arrays[0]["2013-04-09"]; //stable way don't swap with next val
$arrays[1]["2013-04-09"]; //stable way don't swap with next and prev vel
$arrays[4]["2013-04-09"]; //stable way, don't swap with prev val
$arrays[2]["2013-04-11"];
Can you help me? I try create own function of sort beacause ksort or krsort sort using only first dim key. Thank you for answers.
EDIT: I try write my own function - and this works - I got wrong "valid answers" in my units test and this is reason that I said that this isn't works:
private function getResult(){
...
usort($arrays,array($this,'mycmp'));
...
}
private function mycmp($a, $b){
foreach($a as $key=>$val){
$first = $key;
}
foreach($b as $key=>$val){
$second = $key;
}
if ($first == $second){
return 0;
}
return ($first < $second) ? -1:1;
}
THANKS FOR HELP