PHP:使用爆炸scandir时未定义的偏移量

<?php
$dir = "user/jas527/uploads/";
$a = scandir($dir);
for($i=2;$i<$a;$i++){
print_r(explode('.',$a[$i]));
}
?>

i'm trying to explode file names of a directory. but i got a error.

Make correction like this

   for($i=2; $i<count($a); $i++){

scandir returns an array of files and directories from the directory (ref). You need the length of the array for the for-loop. You can get this with count().

scandir

count

Change your for-loop to

<?php
$dir = "user/jas527/uploads/";
$a = scandir($dir);
// for($i=2;$i<$a;$i++){
for($i=2; $i<count($a); $i++){
    print_r(explode('.',$a[$i]));
}

scandir returns an array of files and directories from the directory.SO you have to get total number of elemeny.You forget count to get total number of element in array

for($i=2;$i<count($a);$i++){

Read count()

use foreach instead of for, you do not know how many files are in there, and its so simple to use foreach .

foreach($a as $file){
    print_r(explode('.',$file));
}