示例讲解PHP函数preg_grep()的使用
Jun 13, 2016 am 11:07 AM
grep
php
for
introduce
use
function
us
of
Example
explain
我们今天为大家介绍的PHP函数preg_grep()就是PHP语言中,众多功能强大的函数之一,希望大家在阅读后能够对这一函数优异个深刻的认识。
函数原型:array preg_grep (string $pattern, array $input)
PHP函数preg_grep()返回一个数组,其中包括了$input数组中与给定的$pattern模式相匹配的单元。对于输入数组$input中的每个元素,preg_grep()也只进行一次匹配。代码6.3给出的示例简单地说明了preg_grep()函数的使用。
PHP函数preg_grep()代码6.3 数组查询匹配
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><span> ?php </span></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> </li> </ol>
Copy after login
通过以上这段PHP函数preg_grep()的代码示例,希望能够为读者起到一个加深印象的作用。
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

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
