remove a key if value matches a pattern?

前端 未结 2 1979
小鲜肉
小鲜肉 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 10:37

    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);
    

提交回复
热议问题