0
 <?
    if ($directory = opendir('data/')) { // Open dir    
    while (false !== ($files = readdir($directory))) { //Read directory
        if ($files != "." && $files != "..") { //Strip . and ..
        $files = str_replace("122.","",$files); // Remove 122.
        $files = str_replace("234.","",$files); // Remove 234.
        echo "$files<br />"; // Get results
        }
      }
      closedir($directory); // close directory
    }

?>

目录中的文件为:122.256879、234.4263、122.4263、234.256879

我得到结果:256879 4263 4263 256879

但我需要独特的结果:256879 4263

如何得到这个结果?

4

1 回答 1

1
<?
    $aFiles = array();
    if ($directory = opendir('data/')) { // Open dir    
    while (false !== ($files = readdir($directory))) { //Read directory
        if ($files != "." && $files != "..") { //Strip . and ..
        $files = str_replace("122.","",$files); // Remove 122
        $files = str_replace("234.","",$files); // Remove 234

        if(in_array($files, $aFiles) == false){
            echo "$files<br />"; // Get results
            $aFiles[] = $files;
         }
        }
      }
      closedir($directory); // close directory
    }

?>
于 2013-10-21T13:36:14.080 回答