I think I may have fixed it. Well, it is working without the error. Here is what I did. I added $image_ids = array();
to the code, so it looks like this:
<?php
$image_ids = get_field('gallery', false, false);
$image_ids = array();
$shortcode = '
[gallery ids="' . implode(',', $image_ids) . '"]
';
echo do_shortcode( $shortcode );
?>
The documentation should include this