<html>
<! Recursion.php                                              >
<! Chapter 7, Oracle Database XE PHP Web Programming          >
<! by Michael McLaughlin                                      >
<!                                                            >
<! This script demonstrates defining a recursive function     >
<! with a formal parameter while using flexible parameter     >
<! validation.>
<head>
<title>
  Chapter 7 : Recursion.php [Linear Recursion with Factorials]
</title>
</head>
<body>
<?php
  // Call the recursive program.
  print "[factorial(7)] = [".factorial(7)."]<br>";

  // Define a recursive function that returns an double.
  function factorial($var)
  {
    // Check number of actual parameters.
    if (count($argv = func_get_args()) == 1);
    {
      if ($argv[0] <= 1)
        return (double) 1;
      else
        return (double) $argv[0] * factorial($argv[0] - 1);
    }
  }
?>
</body>
</html>
