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!

You want to use preg_grep for this :)

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

in_array(preg_match('/^pid\|[0-9]+$/',$your_array),$your_array);

OR

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

if you need to check this particular element i.e. pid|100 then just use in_array('pid|100',$your_array) there is no need to check using regular expression

hope this will help you in solve your problem