$i = 0; foreach ($array as $item) { if ($i % 4 < 3) // ilk 3 echo ''; else // sıradaki sonuncu echo ''; }