05-14-2008, 04:51 PM
|
#5 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 753
Thanks: 2
|
You could also calculate the remainder another way which negates the need to check for the case where the cells fit nicely into the grid. It's just another way of doing the same thing.
PHP Code:
function remaining_cells($cells, $cols)
{
return ($cols * ceil($cells / $cols)) - $cells;
}
// Example use: $cells = 17; $cols = 4; ... remainder = 3;
str_repeat('<td> </td>', remaining_cells($cells, $cols);
Good work on refactoring your original 13 lines function down to 5. 
__________________
|
|
|
|