How can the warning "Division by zero" be avoided in PHP code?

Division by zero can be avoided in PHP code by checking if the divisor is zero before performing the division operation. This can be done using an if statement to handle the case where the divisor is zero and prevent the division operation from being executed.

$dividend = 10;
$divisor = 0;

if ($divisor != 0) {
    $result = $dividend / $divisor;
    echo "Result: " . $result;
} else {
    echo "Division by zero is not allowed.";
}