What are the advantages and disadvantages of using PHP for mathematical calculations like prime number checking?
When using PHP for mathematical calculations like prime number checking, one advantage is that PHP has built-in functions like `gmp_prob_prime` that can efficiently check for prime numbers. However, a disadvantage is that PHP may not be as fast or optimized for complex mathematical operations compared to other languages like C or Python.
function isPrime($num){
if($num <= 1){
return false;
}
for($i = 2; $i <= sqrt($num); $i++){
if($num % $i == 0){
return false;
}
}
return true;
}
$number = 17;
if(isPrime($number)){
echo "$number is a prime number.";
} else {
echo "$number is not a prime number.";
}