Voting

: nine plus zero?
(Example: nine)

The Note You're Voting On

SeanECoates at !donotspam!yahoo dot ca
23 years ago
I just came upon a really good use for array_diff(). When reading a dir(opendir;readdir), I _rarely_ want "." or ".." to be in the array of files I'm creating. Here's a simple way to remove them:

<?php
$someFiles
= array();
$dp = opendir("/some/dir");
while(
$someFiles[] = readdir($dp));
closedir($dp);

$removeDirs = array(".","..");
$someFiles = array_diff($someFiles, $removeDirs);

foreach(
$someFiles AS $thisFile) echo $thisFile."\n";
?>

S

<< Back to user notes page

To Top