Say I have a directory with the following files:
- a_1.csv
- a.csv
- b_1.csv
- b.csv
- something_else.csv
Now I’d like to readdir() this directory and put all the files beginning with a (a.csv, a_1.csv) into array $a and all files beginning with b (b.csv and b_1.csv) into array $b. All the other files should be ignored, e.g. something_else.csv
I thought about iterating through the whole directory and preg_match’ing the filename, but I don’t know if there’s a faster way to do this?
You can use glob http://sg.php.net/glob