Divide php echo rows into 3 columns

here is a little example:

<?php

$result=array('one','two','three','four','five','six','seven','eight','nine','ten');
$colon=3;//how much div
$divid=ceil(count($result)/$colon);//how much per div

for($x=0;$x<count($result);$x++){
  if($x%$divid!=0){ 
    echo ' '.$result[$x];
   }else{ 
    echo ($x==0)? '<div>'.$result[$x]:'</div><div>'.$result[$x];
   }  
}
echo '</div>';

?>

Leave a Comment