从WP_Query for WooCommerce产品中的foreach循环中排除重复项

I have a WP Query to list matching products, like this:

function sku_ean_sizes () {
global $product;

$current_stijlcode = $product->get_attribute( 'pa_stijlcode' );
$current_ean = $product->get_attribute( 'pa_ean' );

$postid = get_the_ID();

    $args = array(
      'post_type' => 'product',
      'orderby' => 'meta_value_num',
        'meta_key' => '_price',
        'order' => 'asc',
      'posts_per_page' => 100,
      'tax_query' => array(
    'relation' => 'OR',
    array(
      'taxonomy' => 'pa_stijlcode',
      'field'    => 'slug',
      'terms'    => $current_stijlcode,
    ),
    array(
      'taxonomy' => 'pa_ean',
      'field'    => 'slug',
      'terms'    => $current_ean,
    )
  )
      );
    $loop = new WP_Query( $args );
    if ( $loop->have_posts() ) {
      while ( $loop->have_posts() ) : $loop->the_post();



global $product;

foreach( wc_get_product_terms( $product->id, 'pa_maat' ) as $attribute_value ){
  echo '<span>' . $attribute_value . '</span>';
}

      endwhile;
    } else {
      // no sku matches found
    }
    wp_reset_postdata();
}

I would like to use the foreach loop to list the found product attributes attached to the products found with the WP Query:

global $product;

    foreach( wc_get_product_terms( $product->id, 'pa_maat' ) as $attribute_value ){
      echo '<span>' . $attribute_value . '</span>';
    }

This code works. However, the $attribute_value variable outputs duplicate records. This makes sense, as multiple products could have the same output.

What adjustment can i make so it excludes duplicate values?

In context; This is to display all available sizes for a specific product.

Updated

You should use a foreach loop to set all the values in an array avoiding duplicates

Then, using implode() PHP function, you will display all attributes term names without duplicates.

This partial code to replace yours, will display the non duplicated attribute term names for all products at once:

$loop = new WP_Query( $args );
if ( $loop->have_posts() ):
    $maat_term_names = array();
    while ( $loop->have_posts() ): 
        $loop->the_post();

        // Set the attribute term names in an array avoiding duplicates
        foreach( wc_get_product_terms( $loop->post->ID, 'pa_maat' ) as $attribute_value ):
            $maat_term_names[$attribute_value] = $attribute_value;
        endforeach;
    endwhile;

    // Sorting (ordering)
    sort($maat_term_names);

    // Here you display attribute term names without duplicates (coma separated)
    echo '<span>' . implode( '</span>, <span>', $maat_term_names ) . '</span> ';

else:
   echo '<span>No SKUs matches found</span>';
endif;

wp_reset_postdata();