How to search in an array with preg_match?

后端 未结 5 1687
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 14:54

How do I search in an array with preg_match?

Example:

 name\         


        
5条回答
  •  醉话见心
    2020-11-27 15:41

    $haystack = array (
       'say hello',
       'hello stackoverflow',
       'hello world',
       'foo bar bas'
    );
    
    $matches  = preg_grep('/hello/i', $haystack);
    
    print_r($matches);
    

    Output

    Array
    (
        [1] => say hello
        [2] => hello stackoverflow
        [3] => hello world
    )
    

提交回复
热议问题