Home  >  Article  >  Backend Development  >  PHP recursive function to find factorial

PHP recursive function to find factorial

WBOY
WBOYOriginal
2016-07-25 08:54:061597browse
  1. function demo($a)
  2. {
  3. if($a > 1)
  4. {
  5. $r=$a*demo($a-1);
  6. }else
  7. {
  8. $r=$a;
  9. }
  10. return $r;
  11. }
  12. $a=6;
  13. echo $a."The value of the factorial".demo($a);
  14. ?>
Copy code

The display result of php recursive function to find factorial: PHP recursive function to find factorial



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn