如何根据条件或字符串搜索数组值并删除它们


How do search array values and remove them based on a condition or string?

  1. 从数组中读取文件名
  2. 在数组值中搜索字符串"-dep",如果任何字符串值包含"-dep",请将其删除
  3. 将数组作为值传递给另一个数组

for($d=0; $d < $files; ++$d)
{
    if(strpos($files[$d], "-dep") === true)
    {
      unset($files[$d]);
    }
}
return array($dnum, $fnum, $dirs, $files);

您可以使用array_filter

我不知道这是否是最好的方法,但我会做这个

foreach($array as $key=$value)
{
    if(strstr($value, '-dep'))
        unset($array[$key]);
}