phparraysloopsscandir

Cannot remove "."/".." from scandir array


I was using scandir to get some filenames into an array and then trying to use an if stmt to slice the "." and ".." from the array if they existed, but that did not work so I tried to only echo the image if the variable was not ".." or "." and that did not work. Example Code Below:

if ($pages[$pageIndex] == "." || $pages[$pageIndex] == "..") {
  array_slice($pages, 0, 2);
  print_r($pages);
}
# And

while ($i < $pagesLength) {
  if ($pages[$pageIndex] != "." || $pages[$pageIndex] != "..") {
    echo "<img src='series/series_" . rawurlencode($_GET['series']) . "/series_" . rawurlencode($newLink) . "/" . rawurlencode($pages[$pageIndex]) . "'>";
    $pageIndex = $pageIndex + 1;
    $i++;
  }
}                            }

They Stayed no matter what I did, How can I get rid of them?

Array Content: array contents


Solution

  • Use a for loop starting at line 2 to skip the . / ...

    for ($i = 2; $i <= $pagesLength; $i++) {
      // do something
    }