<?
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
如何获得此结果?
答案 0 :(得分: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
}
?>