Order multidimensional array recursively at each level in PHP

前端 未结 3 1615
感情败类
感情败类 2020-12-03 21:35

I have an array of this form:

Array
(
    [first_level] => Array
        (
            [dir_3] => Array
                (
                    [subdir_1         


        
3条回答
  •  清歌不尽
    2020-12-03 22:17

    Use a recursive function:

    // Note this method returns a boolean and not the array
    function recur_ksort(&$array) {
       foreach ($array as &$value) {
          if (is_array($value)) recur_ksort($value);
       }
       return ksort($array);
    }
    

提交回复
热议问题