Recursion means you call a function which calls itself to get the job done.
Recursive functions have two parts, the base case and the recursive method.
The base case is the goal which signals that your function stops calling
sort of like the condition in a while loop... but for a function rather than
a loop.

Here is a simple recursive script I posted to this list a while back.

function Get_Tree($directory)
  global $dirs;

  if (substr($directory,-1) != "/")
    $directory = $directory . "/";

  $fh = opendir($directory);
  while ($file = readdir($fh))
    if (is_dir($directory . $file) && $file != ".." && $file != ".")
      $dirs[count($dirs)] = $directory . $file;

When you are done $dirs will be an array of all the directory names
below $directory (the initial value of $directory).  Here the base case
is when you reach a directory without any subdirectories (every $file
fails the if statement).

Anyway, I hope this helps.  If you have any specific questions about
recursion feel free to drop me a line  =P

Sheridan Saint-Michel
Website Administrator
FoxJet, an ITW Company

----- Original Message -----
From: "Andres Montiel" <[EMAIL PROTECTED]>
Sent: Sunday, September 30, 2001 12:23 PM
Subject: [PHP] Recursion

> One of my classes next semester needs me to program using a language
> that does "recurison". I don't really know what this means, though. Can
> PHP do this?
> Thanks!

PHP General Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to