PHP

How to avoid division by zero error in PHP

With PHP 8, we can avoid division by zero error without checking the data. PHP 8 introduces a new function call fdiv() that can be used to skip the Division by zero warning.

$x = 10;
$y = 0;

var_dump(fdiv($x,$y));

# output : float(INF)