Web lists-archives.com

[PHP] I am stumped




Hello;
I have the following code snips from isolated development project:
I have been doing lots of coding similar to this and don't ever remember encountering
this type of problem. I have a working version based on this elsewhere, as well. I saved
this message as a draft while I looked over the working code and accept for variable name
differences and differences in foreach looping construct: file or dir is tested in the looping
construct and not in core gerDirListSingle code.

This is supposed to scan a directory and produce an associative array where the index is the
file listing and the value is either directory or file.

In the loop, $_itr is set to 1 instead of 0 to try and solve the eventual output question, but doesn't
do it in tests.

private function getDirListSingle($_dir)
        {
         $_DR = [];
         if(($_DR = scandir($_dir)) === false)
           {
            self::$_readError[count(self::$_readError)] = $_dir." not scanned";
            return;
           }
         for($_itr = 1; $_itr < count($_DR); $_itr++)
           {
            switch($_DR[$_itr])
               {
                case '.':
                case '..':
                break;
                default:
                if(is_dir(self::$_homePath.'/'.$_DR[$_itr]))
                  {
                   self::$_dirsToRead[$_DR[$_itr]] = 'directory';
                  }
                else
                  {
                   self::$_dirsToRead[$_DR[$_itr]] = 'file';
                  }
                 break;
                }
             }
         }

next is code to produce a string representation  of the array:
($_list['dirs'] is a copy of self::$_dirsToRead)

foreach($_list['dirs'] as $_ind=>$_val)
  {
   $_outList[count($_outList)] = $_val.": ".$_ind;
  }
$_out = implode($_outList, "\n");

The following is the result:
testBed is the directory being read for this
Why is testBed/test_1 included and the value is 1
instead of 'directory'. At the bottom of the list is test_1 listed as a file.
Perhaps I have gone blind and can't see a mistake I should be seeing.

// $_out printed out:               
1: testBed/test_1
file: hello.txt
file: hello_1.txt
file: index.php
file: test_1


Thanks for time and attention;
JK
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php