PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jwalsh
Forum Contributor
Posts: 202 Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH
Post
by jwalsh » Tue Apr 25, 2006 2:47 pm
Seeing unexpected results with the following code.
Code: Select all
// READ ALL FILES FROM DIRECTORY
$directory = scandir($filepath);
var_dump($directory);
foreach ($directory as $file)
{
echo $file . "\n";
}
var_dump shows 2 files in the directory, plus "." and "..", but the foreach isn't iterating the last element.
Ouput:
Code: Select all
***** VAR DUMP *****
array(4) {
[0]=>
string(1) "."
[1]=>
string(2) ".."
[2]=>
string(14) "core.class.php"
[3]=>
string(18) "registry.class.php"
}
***** FOREACH *****
.
..
core.class.php
dibyendrah
Forum Contributor
Posts: 491 Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:
Post
by dibyendrah » Wed Apr 26, 2006 1:09 am
works perfect for me. What is the problem there ? I didn't understand the last element you're talking about.
Dibyendra
myoung1620
Forum Newbie
Posts: 3 Joined: Tue Apr 18, 2006 2:15 pm
Location: VA
Post
by myoung1620 » Wed Apr 26, 2006 11:26 am
maybe an alternative will suffice....
Code: Select all
$mydir = "/your_dir";
$dir_handle= opendir($mydir );
while (false !== ($filename = readdir($dir_handle))) {
print "{$filename} <br />";
}