1 回答

TA貢獻1821條經(jīng)驗 獲得超6個贊
用于in_array()測試每個類別,而不是array_diff()在整個數(shù)組上使用。
$excl_categories = array('Offside','2019'); // contains elements that should be excluded
$filtered_files = [];
$filtered_categories = [];
foreach($blogfiles as $blogfile) { // Loop through the blogfiles in the directory
$lines = file($blogfile, FILE_IGNORE_NEW_LINES); // all lines of the txt file into an array
$category = $lines[1]; // category line (2nd line in txt file)
if (!in_array($category, $excl_categories)) {
$filtered_categories[] = $category;
$filtered_files[] = $blogfile;
}
}
- 1 回答
- 0 關(guān)注
- 164 瀏覽
添加回答
舉報