<?phpfunction theme_columns_checkboxes($e) {$options = $e['#options'];// Set the default if no columns are given.if (!isset($e['#columns'])) {$e['#columns'] = 8; }// Set the column number if less than the set amount.if (count($options) < $e['#columns']) {$e['#columns'] = count($options); }$rows = array(); foreach ($options as $key=>$value) {$row[] = theme_checkbox($e[$key]); if (count($row) == $e['#columns']) {array_push($rows,$row);$row = array(); } }// This flushes out the columns when the items don't divide evenly into the columns.if (count($row)) {array_push($rows,$row); } return theme_table(NULL, $rows);}?>

This is pushing items into a theme_table function, but there are other ways to print them out. This method avoids having to keep track of too many variables and depend a little more on the core functions.

Here is an alternate way that doesn't use a table (note that this function is also not using the additional columns variable):