Create / Close Div in Array [closed]

You don’t need to count or do all the stuff to determine the last element. Check if the result of the function is valid, output the DIV and then inside that run a loop:

<?php

    // Get the terms
    $terms = get_the_terms( $post->ID, 'people' );

    // Check if there's any results, and there's no error.
    // If so, output the opening and closing DIV and UL
    if ( $terms && ! is_wp_error( $terms ) ) { ?>

        <div class="card-header text-white bg-success">Team</div>

        <div class="card">
            <ul class="list-group">
                <?php
                    // Now time to output the terms themselves
                    foreach ( $terms as $term ) { ?>
                        <li class="list-group-item border-0">
                            <?php echo esc_html( $term->name ) ?>
                        </li><?php
                    }

                ?>
            </ul>
        </div><?php
    }

?>