It almost works but because he is missing the “not” operator it fails to add the first entry. Here is the pseudo code.
$gallery_array = get_field($key, $post_id, false);
if (!is_array($gallery_array )) {
$gallery_array = array();
}
$gallery_array [] = $img_attachment_id;
update_field($key, $gallery_array , $post_id);