public static function flattenAssoc(array $array, $depth = INF) : array
    {
        $result = [];
        $depth = is_int($depth) ? max($depth, 0) : INF;

        foreach ($array as $key => $value) {
            if (is_array($value) && $depth >= 1) {
                $result = self::flattenAssoc($value, $depth - 1) + $result;
            } else {
                $result[$key] = $value;
            }
        }

        return $result;
    }
public static function flattenAssoc(array $array, $depth = INF) : array
    {
        $result = [];
        $depth = is_int($depth) ? max($depth, 0) : INF;

        foreach ($array as $key => $value) {
            if (is_array($value) && $depth >= 1) {
                $result = self::flattenAssoc($value, $depth - 1) + $result;
            } else {
                $result[$key] = $value;
            }
        }

        return $result;
    }
public static function flattenAssoc ( array $ array , $ depth = INF ) : array { $ result = [ ] ; $ depth = is_int ( $ depth ) ? max ( $ depth , 0 ) : INF ; foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) && $ depth >= 1 ) { $ result = self :: flattenAssoc ( $ value , $ depth - 1 ) + $ result ; } else { $ result [ $ key ] = $ value ; } } return $ result ; }
Flatten a multi-dimensional array into a single level with saving keys

@param  array $array
@param  int   $depth

@return array
Flatten a multi - dimensional array into a single level with saving keys