Group results if meta_value is the same

I would like to group the results of my query if the meta_value is the same for any results. I would expect an output like this:

Group 1
- 1111
- 1111
- 1111

Group 2
- 1234
- 1234

Here is my query:

Read More
$args = array(
    'post_type'  => 'product-api',
    'orderby'    => 'title',
    'order'      => 'ASC',
    'posts_per_page' => -1,
    'meta_query' => array(
        array(
            'key'     => 'last_updated',
            'value'   => '',
            'compare' => '!=',
        )

    ),
);

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) {

    while ( $the_query->have_posts() ) {
        $count++;
        $the_query->the_post(); 
        $model = get_post_meta(get_the_id(), 'product_model', true);
        echo $model;

    }

}

wp_reset_postdata();

What would be the best approach to achieve this?

Related posts