I did do my due diligence and checked out php.net's manual but it's answer didn't work.
This is the code I have. Here, I am making an array of file names. There is more to it but I didn't include any unnecessary code.
while (($filename = readdir($directory_handle)) !== false) {
if (($file != ".") && ($file != "..")) {
$file_array[$i] = $filename;
}
$i++;
}
The output it generates is:
Array ( [0] => .. [1] => . [2] => file1.jpg [3] => file2.jpg )
Why does it not skip making array elements for ".." and "."?
I have tried this various different ways to no avail. Here are things I tried:
1). I tried array_search() + unset() to remove them, but although that did remove "." it still left me with the ".." element. (I tried changing them in the search order, thinking that removing . first might have truncated .. to . and therefore prevented it's key from being unset, but changing the search order didn't solve the problem).
2). I tried copying and pasting the ".." (in case that phrase might contain special characters) and sent that through my array_search() + unset() function, but that did not remove them.
3.) I tried copying and pasting the fix for this directly from php.net and even that did not work. I added some parentheses, thinking it might be better to use slightly clearer syntax, (as you can see above, that is the copied and pasted version with parentheses added) but this did not help.
Because I am trying to remove dots, but could not search for the dots themselves on Google, I could not find any mention of this on the internet. Therefore, I will leave these terms for the next person who does a web search on this topic:
dots
double dots
two dots
periods