What potential pitfalls should be considered when using the Modulo Operator in PHP for checking divisibility?
When using the Modulo Operator in PHP for checking divisibility, one potential pitfall to consider is the possibility of division by zero. This can lead to a division by zero error which will cause the script to halt. To avoid this issue, it is important to check if the divisor is not zero before performing the modulo operation.
$dividend = 10;
$divisor = 0;
if ($divisor != 0) {
if ($dividend % $divisor == 0) {
echo "Divisible";
} else {
echo "Not Divisible";
}
} else {
echo "Cannot divide by zero";
}