How to create a multidimensional array with multiple loops

I don’t think this is a restrict WordPress question, but you might try

$args = array(
    'posts_per_page' => '-1',
    'post_type' => 'work',
    'orderby' => 'ID',
    'order' => 'DESC',
);

$data = array('work' => array());

$loop = new WP_Query($args);
if( $loop->have_posts() ):
    while( $loop->have_posts() ): $loop->the_post();
        $id = $loop->post->ID;

        $attachments=array();
        if(get_field('work')): 
           while(has_sub_field('work')):
              $attachment_id = get_sub_field('image');
              $caption = the_sub_field('caption');
              $image = wp_get_attachment_image_src( $attachment_id, 'work' );   
              $attachments[$attachment_id]=array("caption"=>$caption,"url"=>$image); 
           endwhile;    
        endif; 

        $data['work'][$id] = array(
            'title' => apply_filters( 'the_title', $loop->post->post_title ),
            'content' => apply_filters( 'the_content', $loop->post->post_content ),           
            'items'  => $attachments;  
        );
    endwhile;
endif;
wp_reset_postdata();