Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP preg_grep() Function

PHP preg_grep() Function

PHP Regular Expressions (PCRE)PHP Regular Expressions (PCRE)

The preg_grep function returns the array entries that match a pattern.

Syntax



array preg_grep ( string $pattern , array $input [, int $flags = 0 ] )

Returns an array consisting of the elements of the given array input that match the pattern.

Parameter Description:

Example

Return the elements in the array that match the specified pattern:

The execution result is as follows:



Array

(

    [2] => 3.4

    [4] => 7.9

)

It can be seen that preg_grep only returned the floating-point numbers in the array.

PHP Regular Expressions (PCRE)PHP Regular Expressions (PCRE)