function factorial($number) { if ($number == 0) return 1; return $number * factorial($number - 1); } PHP: On the internet I have found this function which states the factorial of a number. I now want to make a function where basically there will be a user inputted number say x and a power y, but then i want to add x^y to x^y-1 ... x^y-y+1 where y-y+1 is one. This could be used in non-repetitive combinations for example where for a 4 length combination with 10 possible values for each digit would be 10^4 + 10^3 + 10^2 + 10^1 = 10000 + 1000 + 100 + 10 = 11110 Thanks
<?php function combination($number, $number2) { if ($number == 0) return; return pow($number2, $number) + combination($number - 1, $number2); } echo combination(4, 10); ?> PHP: Output: 11110 It should guide you to where you want to go. Rep is appreciated Jay
function factorial($number,$number2) { if ($number == 0) return 1; else { $sum=0; for ($i=$number2;$i>=1;$i--) { $sum=pow($number,$i)+sum; } return $sum; } }