foreach repeat html structure after every nth for attachment [closed]

ok, basicly.
you need this logic

<?php
  if (($a % 2) == 1)
  { echo "$a is odd." ;}
  if (($a % 2) == 0)
  { echo "$a is even." ;}
?>

you’ll loop like you do.
but indeed keep a counter. and check accordingly. I changed your code without testing.

    <?php
    function dt_attached($postid=0, $size="thumbnail", $attributes="", $linksize="full", $count=-1) {
        if ($postid<1) $postid = get_the_ID();
        if ($images = get_children(array(
            'post_parent' => $postid,
            'post_type' => 'attachment',
            'numberposts' => $count,
            'post_mime_type' => 'image',)))

    //declare some counter var
       $counter = 0;

            foreach($images as $image) {
                $attachment=wp_get_attachment_image_src($image->ID, 'thumbnail');
                $small_image = wp_get_attachment_image_src($image->ID, 'midium');
                $big_image = wp_get_attachment_image_src($image->ID, 'full');
               // everytime raise your counter + 1
                $counter=  $counter+1; //you can use  $counter+=1; also 
                ?>
    // this part you only want every 2 rows 
<?php       
if (( $counter % 2) == 1){
 if ($counter > 1) {
  $uneven = true;     
      echo '</div>' ; // your closing div
}
   echo '<div class="mainrow">'; // opening div
 }

    //this part you want every time so no need to check it 
    ?>
                    <div class="block">
                        <a href="https://wordpress.stackexchange.com/questions/61810/<?php echo $big_image[0]; ?>" class="cloud-zoom-gallery" title="Thumbnail 1" rel="useZoom: 'zoom1', smallImage: '<?php echo $small_image[0]; ?>' ">
                            <img src="<?php echo $attachment[0]; ?>" <?php echo $attributes; ?> />
                        </a>
                    </div> <?php
  if ($uneven && $counter == count($images)){ // $count is your amount of attach ?>
                    <div class="block">
                       <!--your empty image code -->
                        </a>
                    </div> <?php } ?>

</div>
     <?php }
    }
    ?>