The html should look something like this:

<div class="slide"> <div class="ph1"><img src="img/hotel/ph1.png" alt="" /></div> <div class="ph2"><img src="img/hotel/ph2.png" alt="" /></div> <div class="ph3"><img src="img/hotel/ph3.png" alt="" /></div> <div class="ph4"><img src="img/hotel/ph4.png" alt="" /></div> </div> <div class="slide"> <div class="ph1"><img src="img/hotel/ph1.png" alt="" /></div> <div class="ph2"><img src="img/hotel/ph2.png" alt="" /></div> <div class="ph3"><img src="img/hotel/ph3.png" alt="" /></div> <div class="ph4"><img src="img/hotel/ph4.png" alt="" /></div> </div> 

In php I did this:

 <?$countmorephoto = 1;?> <?foreach ($arrayimg as $keyimg => $imgmore):?> <?$keyimg++;?> <?if ($countmorephoto == 1){?> <div class="slide"> <?}?> <div class="ph<?=$countmorephoto?>"><img src="<?=$imgmore?>" alt="" /></div> <?if ($countmorephoto == 4 || $countmorephoto == 8 || $countmorephoto == 12 || $countmorephoto == 16){?> <?$countmorephoto = 0;?> </div> <div class="slide"> <?}?> <?if (!next($arrayimg)):?> </div> <?endif;?> <?$countmorephoto++;?> <?endforeach;?> 

But honestly it doesn't really work :)

How best to divide by 4 images, knowing that they can not be more than 16.

    2 answers 2

    You will not believe:

     <? $n = 0; foreach ($arrayimg as $keyimg => $imgmore) { $n++; if ($n % 4 == 1) { ?><div class="slide"><? } ?><div class="ph<?=$n?>"><img src="<?=$imgmore?>" alt="" /></div><? if ($n % 4 == 0) { ?></div><? } } if ($n % 4 > 0) { ?></div><? } ?> 

      Do you always write a new line enclosing it in <??>?

      To you on govnokod , forgive of course.

       <?$countmorephoto = 1;?> <?foreach ($arrayimg as $keyimg => $imgmore):?> <?$keyimg++;?> <?if ($countmorephoto == 1){?> <div class="slide"> <?}?> <div class="ph<?=$countmorephoto?>"><img src="<?=$imgmore?>" alt="" /></div> <?if ($countmorephoto == 4 || $countmorephoto == 8 || $countmorephoto == 12 || $countmorephoto == 16){?> <?$countmorephoto = 0;?> </div> <div class="slide"> <?}?> <?if (!next($arrayimg)):?> </div> <?endif;?> <?$countmorephoto++;?> <?endforeach;?> 
      • one
        really hard ) - Palmervan
      • And I'm talking about. - Artem
      • 2
        Do not use in php || // don't do it! 11! ADIN // use or - Zowie
      • and the difference? Well, the priorities are different, but everyone should know that! - Alex Kapustin
      • one
        @shurik, this is the same: if ($ countmorephoto == 4 || $ countmorephoto == 8 || $ countmorephoto == 12 || $ countmorephoto == 16) if ($ countmorephoto == (4 || $ countmorephoto) == (8 || $ countmorephoto) == (12 || $ countmorephoto) == 16) Y == priority 7, y || - 2. Therefore, either in brackets or OR . By the way, he only recently comprehended this thing, wrote everything with a huge number of brackets) - Sh4dow