I am while using PHP code below to show CSS classes in line with the custom taxonomies put on my WordPress posts. My taxonomy is known as CC and it is three choices are x, y, and z. For any publish which has the 3:

 $cc_terms=get_the_terms($post->ID,'cc');
 foreach($cc_terms as $term){echo ' '.$term->slug.'-active';}

results: x-active y-active z-active

I am attempting to convert it into WordPress shortcode function (where echo does not work so far as I understand) and essentially I have to learn how to capture cc_class() as you variable (no array) to ensure that it produce exactly the same output as above.

function cc_meta( $atts, $content = null ) {
    global $post;
    extract(shortcode_atts(array('class' => 'default'), $atts));
    function cc_class() {
        $cc_terms=get_the_terms($post->ID,'cc');
        foreach($cc_terms as $term){return ' '.$term->slug.'-active';}
        }
    $cc_meta = '<div class="' . esc_attr($class) . cc_class() . '">...</div>';
    return $cc_meta;
    }

results: <div class="default x-active">...</div>

It's only using the first term instead of the 3, making me question how return works in foreach loops. Any idea the way i can get this work?

preferred output: <div class="default x-active y-active z-active">...</div>

UPDATE 1:

I attempted using the .= as recommended and I am obtaining a blank error:

function cc_meta( $atts, $content = null ) {
    global $post;
    extract(shortcode_atts(array('class' => 'default'), $atts));

        $cc_terms=get_the_terms($post->ID,'cc');
        foreach($cc_terms as $term){$return .= ' '.$term->slug.'-active';}

    $cc_meta = '<div class="' . esc_attr($class) . $return . '">...</div>';
    return $cc_meta;
    }

UPDATE 2:

I removed the global $post line also it works—sweet! Thanks everybody =)

function cc_meta( $atts, $content = null ) {
    extract(shortcode_atts(array('class' => 'default'), $atts));

        $cc_terms=get_the_terms($post->ID,'cc');
        foreach($cc_terms as $term){$return .= ' '.$term->slug.'-active';}

    $cc_meta = '<div class="' . esc_attr($class) . $return . '">...</div>';
    return $cc_meta;
    }

Don't return in the center of your function, use return limited to the finish.

Rather than return make use of this:

$return .= 

and prior to the closing } perform a return $return;