This question already has an answer here:
- PHP - check if number is prime 17 answers
- The 3 different equals 5 answers
I'm trying to "calculate" a prime number with an if statement and I want to define the calculation in the if statement
<?php
function prime($pNumber){
if (($pNumber%1=$pNumber) && ($pNumber%$pNumber=0)) {
echo $pNumber ." is a prime number.";
}else {
echo $pNumber . "is not a prime number";
}
}
I was expecting that if i call the function with say 6 it would go through the if statement 6%6=0 6%1=0 and yes I know I cant calculate a prime that way. I'm just wondering if I can use an if statement in that way.
Aucun commentaire:
Enregistrer un commentaire