PHP grouping based on a value
The middle else if statement is redundent and can be removed. The reason that is redundent is that the only two cases are either equal or less than 5 balls gives 0 baskets and for everything else the number of baskets can be evaluated to be ceil(count($balls)/12). 

Also using short hand will make it more readable I find. 

$baskets = count($balls) &lt;=5 ? 0 : ceil(count($balls)/12);