Count the number of matching post names in foreach loop

I would get the count of a variable number of repeated titles by using an indexed array.

$theposts = get_posts( array(
    'post_type'   => 'post_subscriber',
    'post_status' => 'publish',
    'numberposts' => -1,
) ); 

// project titles counter, outside the loop
$project_titles = array();

foreach( $theposts as $p ): 

    $project_name = get_post_meta($p->ID, 'project', true);
    echo '<ol>';
        echo '<li class="mb-3">';
            $project_title = get_the_title($project_name);
            echo $project_title;

            // check if $project_titles contains $project_title already
            if ( array_key_exists( $project_title, $project_titles) ) :
            else : // otherwise, initialize key value pair with 1
                $project_titles[$project_title] = 1;
        echo '</li>';
    echo '</ol>';    

// loop through and print all
foreach ($project_titles as $project_title => $project_title_count) :
    if ($project_title_count > 1) : // repeated
        echo 'There are ' . $project_title_count . ' projects with the name ' . $project_title . '.<br/>';

$project_titles will now store the number of times each title is repeated as a key-value pair. The key will be your project’s title, and the value will be the number of times that project’s title exists.

EDIT: Removed first code block since it wasn’t useful with question update. Updated second block of code to accommodate a variable number of repeated titles.