php - php |通过正则表达式在数组中查找

标签 php regex

我正在寻找在字符串数组中找到一个字符串的方法:

$array = ['string1'=>'custom', 'other string'=>'another', 'another'=>'again', 'custom'=>'pid|100', 'once again'=>'pid|'];

我需要找到此元素: pid | 100 ;

字符串应包含: pid |任何正整数
foreach($array as $value) { 
   // regular expression here
}

如何找到该值?
谢谢!

最佳答案

您想为此使用preg_grep :)

print_r(preg_grep('/^pid\|[0-9]+$/',$array));

关于php - php |通过正则表达式在数组中查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30367620/

相关文章:

php - jQuery:提交表单之前的 Ajax

php - 有没有比 VALUES($var1, $var2, $var3) 更好的方法向 MySQL 查询插入值?

php - sha1() 用于密码哈希

javascript - 使用 Bootstrap 3.1 在 IE9 中无法加载 CSS 压缩

java - 如何转换以下字符串中的分隔符

javascript - 在 Javascript 中验证带有时间偏移量的日期时间字符串

php - 如何从递归函数返回数组

python - 用于查找 { } 内所有文本的正则表达式,包括空格和换行符

java - 如何判断给定的字符串是否为 RSS feed

java - 如何从 Java 中比较的两个字符串中返回不常见的字符