Shortcode with foreach

You’re trying to concatenate a foreach statement in to a string, which can’t be done… You need to add the output that you need to your existing string, not concatenate it

function create_galeri_shortcode( $atts ) {

    $atts = shortcode_atts(
        array(
        ),
        $atts,
        'galeri'
    );

    if ( has_post_format( 'gallery' ) ) {
        $images = get_post_meta( get_the_ID(), 'vdw_gallery_id', true );
        if( $images ) {
            $out="<div id="lightgallery">".
            foreach ($images as $imageid) {
                $altyazi = get_post_meta( get_the_ID(), '_wp_attachment_image_alt', true );
                $out .= '<a href="'.wp_get_attachment_url($imageid, 'large').'" data-sub-html=".caption">';
                    $out .= '<img src="'.wp_get_attachment_url($imageid, 'thumbnail').'" alt="'.$altyazi.'">';
                    $out .= '<div class="caption">';
                        $out .= '<h4>'.$altyazi.'</h4>'; 
                        $out .= '<p>'.wp_get_attachment_caption( $imageid ).'</p>';
                    $out .= '</div>';
                $out .= '</a>';
            }
            $out .= '</div>';
        }
    }
return $out;
}
add_shortcode( 'galeri_mm', 'create_galeri_shortcode' );