function noOfPermutations($n, $permutation){
$array = str_split($n);
if(count($array)==1) {
echo $permutation."\n";
return $permutation;
}else{
$permutation++;
noOfPermutations(array_sum($array), $permutation);
}
}
echo "--".noOfPermutations(91,0)."--\n";
I'm trying to find the number of permutations for the sum of the digits in $n becomes single. e.g. 91 -> 9+1 = 10 -> 1+0 = 1. This took 2 rounds so would return 2. The function works fine if $n starts as a single digit number (it correctly returns 0) however more than one permutation and it just returns null. The first echo in the function outputs the correct value but the echo outside the function returns null.