Example to explain the use of PHP function preg_grep()_PHP tutorial

WBOY
Release: 2016-07-15 13:30:57
Original
1994 people have browsed it

The PHP function preg_grep() we introduce to you today is one of the many powerful functions in the PHP language. I hope you can have a deep understanding of this function after reading it.

Function prototype: array preg_grep (string $pattern, array $input)
PHP function preg_grep() returns an array, which includes the cells in the $input array that match the given $pattern pattern . Preg_grep() also only performs a match for each element in the input array $input. The example given in Listing 6.3 simply illustrates the use of the preg_grep() function.

PHP function preg_grep() code 6.3 Array query matching

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>$</span><span class="attribute">subjects</span><span> = </span><span class="attribute-value">array</span><span>(  </span></li><li class="alt"><span>"Mechanical Engineering", "Medicine",  </span></li><li><span>"Social Science", "Agriculture",  </span></li><li class="alt"><span>"Commercial Science", "Politics"  </span></li><li><span>);  </span></li><li class="alt"><span>//匹配所有仅由有一个单词组成的科目名  </span></li><li><span>$</span><span class="attribute">alonewords</span><span> = </span><span class="attribute-value">preg_grep</span><span>("/^[a-z]*$/i"<br />, $subjects);  </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li></ol>
Copy after login

Through the above code example of PHP function preg_grep(), I hope it can deepen the impression for readers.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446250.htmlTechArticleThe PHP function preg_grep() we introduce to you today is one of the many powerful functions in the PHP language. I hope everyone can have a deep understanding of this function after reading it. Letter...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!