PHP preg_grep() Funksie
Voorbeeld
Kry items uit 'n skikking wat met "p" begin:
<?php
$input = [
"Red",
"Pink",
"Green",
"Blue",
"Purple"
];
$result = preg_grep("/^p/i", $input);
print_r($result);
?>
Definisie en gebruik
Die preg_grep()
funksie gee 'n skikking terug wat slegs elemente van die invoer bevat wat by die gegewe patroon pas.
Sintaksis
preg_grep(pattern, input, flags)
Parameterwaardes
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. |
Tegniese besonderhede
Terugkeerwaarde: | Wys 'n skikking wat stringe bevat wat by die verskafde patroon pas |
---|---|
PHP weergawe: | 4+ |
❮ PHP RegExp-verwysing