How to get the name of the parent menu if the current page is an archive page in a custom menu

https://stackoverflow.com/questions/52006212/how-to-get-current-page-menu-item-ancestor-name-wordpress

I found a solution through the answers to the above questions.

function my_menu_parent($theme_location) {
    $locations = get_nav_menu_locations();
    if ( isset( $locations[ $theme_location ] ) ) {
        $menu = wp_get_nav_menu_object( $locations[ $theme_location ] );
        $menu_items = wp_get_nav_menu_items($menu->term_id);
        _wp_menu_item_classes_by_context( $menu_items );
        $breadcrumbs = array();

        foreach ( $menu_items as $menu_item ) {         
            if ($menu_item->current_item_ancestor) {
                $breadcrumbs[] = $menu_item->title;
            }
        }

        return $breadcrumbs;
     }
}
<?php
$parentitems = my_menu_parent( 'menu-1' );
foreach ( $parentitems as $parentitem ) {
    echo $parentitem."<br>";
}