Funkce PHP preg_grep().
❮ Referenční příručka PHP RegExp
Příklad
Získejte položky z pole, které začíná „p“:
<?php
$input = [
"Red",
"Pink",
"Green",
"Blue",
"Purple"
];
$result = preg_grep("/^p/i", $input);
print_r($result);
?>
Definice a použití
Funkce preg_grep()
vrací pole obsahující pouze prvky ze vstupu, které odpovídají danému vzoru.
Syntax
preg_grep(pattern, input, flags)
Hodnoty parametrů
Parameter | Description |
---|---|
pattern | Required. Contains a regular expression indicating what to search for |
input | Required. An array of strings |
flags | Optional. There is only one flag for this function. Passing the
constant PREG_GREP_INVERT will make the function return
only items that do not match the pattern. |
Technické údaje
Návratová hodnota: | Vrátí pole obsahující řetězce, které odpovídají zadanému vzoru |
---|---|
Verze PHP: | 4+ |
❮ Referenční příručka PHP RegExp