public static function mapKeys(callable $function, array $array)
    {
        $new_array = array();
        foreach ($array as $key => $value) {
            $result = call_user_func($function, $value, $key);
            if (is_array($result)) {
                if (1 === count($result)) {
                    // Only returned a value, no key, so keep existing key.
                    $new_array[$key] = array_shift($result);
                } elseif (2 === count($result)) {
                    // Returned a key and a value, so set a new key.
                    $new_array[array_shift($result)] = array_shift($result);
                }
            }
            unset($result);
        }
        return $new_array;
    }