<?php

$arr=array(
   "test 1",
   "test 2",
   "test 3",
   "test 4",
   "test 5",
   "test 6",
   "test 7",
   "test 8",
   "test 9",
   "test 10",
   "test 11",
   "test 12",
);
 
?>

<?php $counter = 0; ?>
<?php foreach ($arr as $key => $value) { ?>

   <?php if( $key % 5 == 0 ) { ?> <ul> <?php } ?>
      <?php $counter++; ?>
      <li><?=$value?></li>
   <?php if( $counter == 5 ) { ?> </ul> <?php $counter = 0; } ?>

<?php } ?>
<?php if( $counter != 0 ) { ?> </ul> <?php } ?>
Çok iyi kodlama olmasa da iş görür