Thanks IThinkMyBrainHurtsI guessed something like this. But why should I go for such complexity?
Please consider this code to test the primality:
function is_prime($num)
{
for($i=2; $i<= (int)sqrt($num); $i++){
if($num % $i == 0) {
return false;
}
}
return true;
}
if(is_prime(119)){
echo 'Prime';
}
else {
echo 'Not Prime';
}
//output not prime

I had searched web and found some of them very interesting and few of them seem complex like this one in wiki:
function isPrime($n) {
if ($n <= 3) {
return $n > 1;
} else if ($n % 2 === 0 || $n % 3 === 0) {
return false;
} else {
for ($i = 5; $i * $i <= $n; $i += 6) {
if ($n % $i === 0 || $n % ($i + 2) === 0) {
return false;
}
}
return true;
}
}
Specially this part:
for ($i = 5; $i * $i <= $n; $i += 6) {
if ($n % $i === 0 || $n % ($i + 2) === 0) {
return false;
}
}
It started from 5. It is okay. But the logic flow seems pretty complex. Can anyone translate in simple English actually what is happening?

I have written a function to check whether any number is prime or not.
Is it okay? or I can better it by any means?
function isPrime($num){
$number = array();
for ($i=2; $i <= $num; $i++){
if(($num%2)==0){
continue;
}
if (($num%$i)==0){
break;
}
$number[]=$i;
}
/*
* how I back calculate to make it successful
foreach ($number as $key => $value) {
echo "$key = $value <br>";
}
echo count($number);
*/
if (count($number)== ($num-2))
{
echo 'it is prime';
}
else {
echo 'not prime';
}
}
isPrime(101112345909);

Yes, I am agreed with Adam. To start with and getting acquainted with the MVC approach, CodeIgniter is fine. Hopefully it will catch up with the advancement taking place in the PHP world; but, till then you can start with CI.

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.