Output all terms in a custom taxonomy and add a “active” class only to the ones attached to the current post


I want to output all the terms in my custom taxonomy and at the same time add a class to any of these that are attached to the current post.

I’ve used get_terms() to show all the terms in the taxonomy but I can’t work out how to check if the term in the loop is active.

$terms = get_terms( array(
    'taxonomy' => 'package',
    'hide_empty' => false
) );

if (!empty($terms) && ! is_wp_error( $terms )) {
  echo '<ul>';
  foreach ($terms as $term) {
    echo '<li>' . $term->name . '</li>';
  }  
  echo '</ul>';  
}