/ Published in: PHP
Expand |
Embed | Plain Text
function factors($n = 0, $array = FALSE) { for ($i = 2; $i <= $n / $i; $i++) { while ($n % $i == 0) { $pf[] = $i; $n = $n / $i; } } if ($n > 1) $pf[] = $n; } // 5 * 11 // Array ( [0] => 5 [1] => 11 )
Comments
Subscribe to comments
You need to login to post a comment.

I don't get it. How it works? When I printed something like factors(55) it just says "array".
I edited the code.
calling factors(55) would return "5 * 11"
calling factors(55, true) would return an array of the factors ex: Array ( [0] => 5 [1] => 11 )