[SOLVED] Proably just a rushed mistake...
Posted: Thu Jan 05, 2006 3:51 pm
I was writing this short peice of code for a friend, but I just can't get it to work! By the way, this code is supposed to return factor trees (not formatted) of numbers.
As you can see, it's pretty simple. But I know I've done something wrong...
Code: Select all
<?php
function is_prime ($inputnum)
{
$i = 1;
while($i<=$inputnum)
{
if(!is_float($inputnum/$i))
{
$factors .= $inputnum/$i.',';
$i++;
} else {
$i++;
}
}
$result = explode(',',$factors);
$count = count($result);
if($count>2)
{
return FALSE;
} else {
return TRUE;
}
}
$number = 10;
$i = 1;
while($i<=$number)
{
$var = $number/$i;
if(is_prime($var) && !is_float($var))
{
$primes .= $var;
$i++;
} else {
$i++;
}
}
echo $primes;
?>