douhan1992 2015-05-21 07:46 采纳率: 100%
浏览 221
已采纳

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

I'm looking the way to find one string in array of strings:

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

I need to find this element: pid|100;

String should containt: pid|any positive integer number

foreach($array as $value) { 
   // regular expression here
}

How can I found this value? Thanks!

  • 写回答

2条回答 默认 最新

  • duanlai1855 2015-05-21 07:49
    关注

    You want to use preg_grep for this :)

    print_r(preg_grep('/^pid\|[0-9]+$/',$array));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?