remove a key if value matches a pattern?

前端 未结 2 1947
小鲜肉
小鲜肉 2020-12-22 09:57

i\'ve got an array with string values.

i want to search for a pattern with regex and if matched, remove the key containing the value.

how would i accomplish

2条回答
  •  囚心锁ツ
    2020-12-22 11:03

    foreach($array as $key => $value) {
        if(preg_match($pattern, $value)) {
            unset($array[$key]);
        }
    }
    

提交回复
热议问题