开发者

remove a key if value matches a pattern?

开发者 https://www.devze.com 2022-12-20 23:21 出处:网络
i\'ve got an array with string values. i want to search for a pattern with regex and if matched, remove the key containing开发者_如何学JAVA the value.

i've got an array with string values.

i want to search for a pattern with regex and if matched, remove the key containing开发者_如何学JAVA the value.

how would i accomplish this?


preg_grep: http://php.net/manual/en/function.preg-grep.php

$a = array('foo' => 'xx', 'bar' => '12');
$b = preg_grep('~[a-z]~', $a, PREG_GREP_INVERT);
print_r($b);


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

精彩评论

暂无评论...
验证码 换一张
取 消