How can conditional statements be used to avoid division by zero errors in PHP scripts?

Division by zero errors can be avoided in PHP scripts by using conditional statements to check if the divisor is zero before performing the division operation. If the divisor is zero, the script should handle the error gracefully, such as by displaying a message to the user or setting a default value instead of attempting the division.

$dividend = 10;
$divisor = 0;

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