从php中的数组中删除重复键

I have this array, and I want to remove the duplicate keys from it.

Array
(
[8] => Array
    (
        [7] => one name
        [27] => Array
            (
                [27] => Array
                    (
                        [31] => other name
                    )

            )

        [10] => Array
            (
                [10] => Array
                    (
                        [24] => Array
                            (
                                [24] => Array
                                    (
                                        [30] => some name
                                    )

                            )

                    )
            )
    )

)

I want to remove the first 27, first 10 and first 24, how can I do it?

The result should be like this

Just remove the duplicates keys

Array
(
[8] => Array
(
    [7] => one name

    [27] => Array
        (
            [31] => other name
        )

    [10] => Array
        (
            [24] => Array
                (
                    [30] => some name
                )
        )
)

)

I got this structure by building a loop function

I don't exactly understand that this array is result of what, neither that this output is used for what. But anyway, here's a simple recursive algorithm that does what you want. There's nothing PHP specific in it by the way.

function remove_duplicates(&$array){
    foreach($array as $key => &$val){

        if(is_array($val)){
            if(count($val) == 1 && array_keys($val)[0] == $key){
                $val = $val[$key];
            }

            remove_duplicates($val);

        }
    }
}

See test run here