如果值与模式匹配,则删除键? [英] remove a key if value matches a pattern?
本文介绍了如果值与模式匹配,则删除键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含字符串值的数组.
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.
我将如何做到这一点?
推荐答案
foreach($array as $key => $value) {
if(preg_match($pattern, $value)) {
unset($array[$key]);
}
}
这篇关于如果值与模式匹配,则删除键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文