0

When we use scandir function.it will display the all the files and directories inside the directory,which we pass in the scandir function as argument. But it also add two more element . and ..

I want to know why these two element is showing?

Rahul
  • 5,603
  • 6
  • 34
  • 57
mjdevloper
  • 1,553
  • 8
  • 33
  • 69
  • 1
    It doesn't __add__ those elements, they're already there as filesystem entries – Mark Baker Jul 19 '13 at 07:08
  • Use `array_values(array_diff(scandir($dir), array('..', '.')))` or `array_diff(scandir($dir), array('..', '.'))` to remove the `.` and `..` from the results. `array_values` makes the index start from 0. – Dan Bray Sep 01 '17 at 15:01

2 Answers2

5

'.' is current directory

'..' is parent directory

Arun Killu
  • 13,581
  • 5
  • 34
  • 61
4

They are directories. The . is the current directory and the .. is the parent directory You can try cd into this directories like this:

cd .

David Lin
  • 13,168
  • 5
  • 46
  • 46