$sum = [0, 0, 0, 0]; echo count($sum) / array_sum($sum); // Warning: Division by zero $arraySum = 0.00001 + array_sum($sum); $number = count($sum) / $arraySum; echo round($number, 2); // Result is 0; Just add some small number to the one you are not sure that it will be bigger than zero. Easy as that.