Recursive function to move a specific key in a multidimensional array to the bottom of his level

I’m looking for a php (sort?)function which move a specific key ('current_files') to the bottom of its array level.

I have sth like that:

[A] => [
     [current_files] => [
           [0] => ...
           [1] => ...  
     ]
     [D] => [
          [G] => [...]   
          [current_files] => [...]
          [B] => [...]
     ]
]
[current_files] => [...]
[K] => [...]

I need this:

[A] => [
     [D] => [
          [G] => [...]   
          [B] => [...]
          [current_files] => [...]
     ]
     [current_files] => [
           [0] => ...
           [1] => ...  
     ]
]
[K] => [...]
[current_files] => [...]

I know that i need a recursive function like arr_multisort but i dont understand it -_-

Answer

Try this

Written a common function just call that function to move down any key by passing the specific key as argument.

function sortArrayByKey(&$array, $search_key) {
    $searched_key_arr = array();
    foreach ($array as $k => &$values) {
        if (array_key_exists($search_key, $values)) {
            sortArrayByKey($values, $search_key);
        } else if ($k == $search_key) {
            $searched_key_arr[$k] = $values;
            unset($array[$k]);
        }
    }
    if (!empty($searched_key_arr)) {
        foreach ($searched_key_arr as $key => $val) {
            $array[$key] = $val;
        }
    }
    return $array;
}

$arr = $this->sortArrayByKey($data, 'current_files'); //$data is your input array
print_r($arr);