是否可以使用PHP函数的正则表达式array_key_exists()?
例如:
$exp = "my regex";  
array_key_exists($exp, $array);
谢谢!
cod*_*ict 34
您可以使用array_keys()提取数组键,然后在该数组上使用preg_grep():
function preg_array_key_exists($pattern, $array) {
    $keys = array_keys($array);    
    return (int) preg_grep($pattern,$keys);
}
.
$arr = array("abc"=>12,"dec"=>34,"fgh"=>56);
var_dump(preg_array_key_exists('/c$/',$arr)); // check if a key ends in 'c'.
var_dump(preg_array_key_exists('/x$/',$arr)); // check if a key ends in 'x'.
function preg_array_key_exists($pattern, $array) {
    // extract the keys.
    $keys = array_keys($array);    
    // convert the preg_grep() returned array to int..and return.
    // the ret value of preg_grep() will be an array of values
    // that match the pattern.
    return (int) preg_grep($pattern,$keys);
}
输出:
$php a.php
int(1)
int(0)
| 归档时间: | 
 | 
| 查看次数: | 12721 次 | 
| 最近记录: |