The PHP function preg_grep () We introduced to you today is one of the many powerful functions in the PHP language. I hope you will have a deep understanding of this function after reading it.
Function prototype: array preg_grep (string $ pattern, array $ input)
The PHP function preg_grep () returns an array containing the units in the $ input array that match the given $ pattern. For each element in the input array $ input, preg_grep () only matches once. The example given in code 6.3 illustrates the use of the preg_grep () function.
PHP function preg_grep () code 6.3 array query matching
- <? Php
- $ Subjects = array (
- "Mechanical Engineering", "Medicine ",
- "Social Science", "Agriculture ",
- "Commercial Science", "Politics"
- );
- // Match the names of all subjects that contain only one word
- $ Alonewords = preg_grep ("/^ [a-z] * $/I"
, $ Subjects );
- ?>
Through the code example of the above PHP function preg_grep (), we hope to serve readers a better impression.