Cleaner way of using modulus for columns

Posted by WmasterJ on Stack Overflow See other posts from Stack Overflow or by WmasterJ
Published on 2010-03-23T21:21:23Z Indexed on 2010/03/23 22:53 UTC
Read the original article Hit count: 223

Filed under:
|
|

I currently have a list (<ul>) of people that I have divided up into two columns. But after finishing the code for it I keept wondering if there is a more effective or clean way to do the same thing.

echo "<table class='area_list'><tr>";
// Loop users within areas, divided up in 2 columns
$count = count($areaArray);
for($i=0 ; $i<$count ; $i++) {
  $uid = $areaArray[$i];
  // get the modulus value + ceil for uneven numbers
  $rowCalc = ($i+1) % ceil($count/2);

  if ($rowCalc == 1) echo "<td><ul>";

  // OUTPUT the actual list item
  echo "<li>{$users[$uid]->profile_lastname}</li>";

  if ($rowCalc == 0 && $i!=0) echo "</ul></td>";
}
echo "</tr></table>";

Any ideas of how to make this cleaner or do it in another way?

© Stack Overflow or respective owner

Related posts about php

Related posts about php5