<?php
// Load value (array of ids).
$image_ids = get_field('gallery');
if( $image_ids ) {
// Generate string of ids ("123,456,789").
$images_string = implode( ',', $image_ids );
// Generate and do shortcode.
// Note: The following string is split to simply prevent our own website from rendering the gallery shortcode.
$shortcode = sprintf( '[' . 'gallery ids="%s"]', esc_attr($images_string) );
echo do_shortcode( $shortcode );
}