PHP CSV Loop through same column name
===

the code below works flawlessly. What im trying to do now is create a few new rows with he same column name "main_img_url" but have a loop set in place to handle the quantity it finds in each row. So if i have 3 or more main_img_url, the loop should know this and add them accordingly. I noted below where the image handler starts and ends.

**Here is an example CSV:**

post_title, post_content, main_img_url, main_img_url

**Here is my code:**

    	function process($file) {
    		$rows = $this->app_csv_to_array($file);
    		foreach($rows as $row) {
    			$post['post_title'] = sanitize_text_field($row['post_title']);
    			$post['post_content'] = sanitize_text_field($row['post_content']);
    			$post['post_status'] = 'publish';
    			$post['post_author'] = 658;
    			$file = $row['main_img_url'];
    				
    		$post_id = wp_insert_post($post);
    		//////////////// I want the loop to start here   //////////////////
    			if ( ! empty($file) ) {
    				$tmp = download_url( $file );
    				preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
    				$filename = strtolower(basename($matches[0]));
    				$exts = split("[/\\.]", $filename);
    				$n = count($exts)-1;
    				$exts = $exts[$n];
    				$renamed = mt_rand( 1000,1000000 ).".".$exts;
    				$file_array['name'] = $renamed;  
    				$file_array['tmp_name'] = $tmp;
    				$overrides = array('test_form'=>false);
    				$file = wp_handle_sideload($file_array, $overrides);
    				if ( isset($file['error']) )
    					return new WP_Error( 'upload_error', $file['error'] );
    				$url = $file['url'];
    				$type = $file['type'];
    				$file = $file['file'];
    				$title = preg_replace('/\.[^.]+$/', '', basename($file));
    				$content = '';
    				$attachment = array(
    					'post_mime_type' => $type,
    					'guid' => $url,
    					'post_title' => $title,
    					'post_content' => $content,
    				);
    				if ( isset( $attachment['ID'] ) )
    					unset( $attachment['ID'] );
    				$id = wp_insert_attachment($attachment, $file, $post_id);
    				if ( !is_wp_error($id) )
    					wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
    			}
    //////////////// ends here   //////////////////
    		}
    	}

