If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
<?php
/*define a function that checks if a given number is prime or not.
* @number int
* return boolean (true/false)
*/
function is_prime($number)
{
if ($number == 1)
return false;
for ($i = 2; $i <= $number/2; $i++)
{
if ($number % $i == 0)
return false;
}
return true;
}
$number = 33;
/*now test*/
if (is_prime($number))
echo "$number is a prime number.";
else
echo "$number is not a prime number.";
echo '<br>';
/*another test*/
$number = 47;
if (is_prime($number))
echo "$number is a prime number.";
else
echo "$number is not a prime number.";
?>
33 is not a prime number. 47 is a prime number.
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook