I had a interesting problem today where I needed to sort an API response that included a list of dates for keys and integers for values. The trick was that the response was an array object, which I couldn’t sort on.

I ended up having to change the array object to a standard array, cycle through the key/value pairs, put them into a new array, and finally sort on that new array.

// Change object to array
$sortedArray = (array) $arrayObject;
// Create a new array to store the new key values
$array = array();
// Cycle through the array and push
// the new keys into the new array
foreach($sortedArray AS $key => $value){
    $key = date('Y-m-d',strtotime($key));
    $array[$key] = $value;
// sort the new array on keys in reverse

Here is the code in action: http://www.tehplayground.com/#g6pelg6ft