View Single Post
Old 05-14-2008, 04:51 PM   #5 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 753
Thanks: 2
Salathe is on a distinguished road
Default

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>&nbsp;</td>'remaining_cells($cells$cols); 
Good work on refactoring your original 13 lines function down to 5.
__________________
Salathe is offline  
Reply With Quote