Home  >  Article  >  Backend Development  >  Detailed explanation of regular expression preg_grep function

Detailed explanation of regular expression preg_grep function

小云云
小云云Original
2018-03-27 09:35:541994browse

This article mainly shares with you the detailed explanation of the regular expression preg_grep function. preg_grep returns an array composed of elements matching the pattern pattern in the given array input. Hope it helps everyone.

##patternRegular expression Formula, pattern to be searched, string form.inputInput array.flagsIf set to PREG_GREP_INVERT, this function returns an array of elements in the input array that do not match the given pattern pattern.
$array = array(1.2, 1.3, 1, 11.1);$fl_array = preg_grep("/^(\d+)?\.\d+$/", $array);
var_dump($fl_array); //array(2) { [0]=> float(1.2) [1]=> float(1.3) }$fl_array = preg_grep("/^(\d+)?\.\d+$/", $array);
var_dump($fl_array); //array(1) { [2]=> int(1) }
Parameter Description
Related recommendations:


(PHP) Regular expression-preg_grep function usage

Example explains the use of PHP function preg_grep()_PHP tutorial

Example to explain the use of PHP function preg_grep()

The above is the detailed content of Detailed explanation of regular expression preg_grep function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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