C implementation of Breadth First Search by faheemlhr

VIEWS: 20 PAGES: 1

									<?php

//a breadth-first file tree traversal

$delim = strstr(PHP_OS, "WIN") ? "\\" : "/";

function retrieveTree($path) {

     global $delim;

     if ($dir = @opendir($path)) {

         while (($element = readdir($dir)) !== false) {

            if (is_dir($path.$delim.$element) && $element != "." &&
$element != "..") {

                 //$array[$element] = NULL;

                 $temp_array[] = $element;

             } elseif ($element != "." && $element != "..") {

                 $array[] = $element;

             }

         }

         if (isset($temp_array)) {

             for ($i = 0; $i < sizeof($temp_array); $i++) {

                 $element = $temp_array[$i];

                 $array[$element] = retrieveTree($path.$delim.$element);

             }

         }

         closedir($dir);

     }

     return (isset($array) ? $array : false);

}

?>

								
To top