English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The preg_grep function is used to return array entries that match the pattern.
array preg_grep ( string $pattern , array $input [, int $flags = 0 ] )
Returns an array of elements that match the pattern in the given array input.
Parameter Description:
<?php
$array = array(1, 2, 3.4, 53, 7.9);
// Returns all elements containing floating-point numbers
$fl_array = preg_grep("/^(\d+)?\.\d+$/", $array);
print_r($fl_array);
?>
The execution result is as follows:
Array ( [2]]=> 3.4 [4]]=> 7.9 )
It can be seen that preg_grep only returns the floating-point numbers in the array.