PHP preg_grep() 함수
예시
"p"로 시작하는 배열에서 항목 가져오기:
<?php
$input = [
"Red",
"Pink",
"Green",
"Blue",
"Purple"
];
$result = preg_grep("/^p/i", $input);
print_r($result);
?>
정의 및 사용
이 preg_grep()
함수는 입력에서 주어진 패턴과 일치하는 요소만 포함하는 배열을 반환합니다.
통사론
preg_grep(pattern, input, flags)
매개변수 값
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. |
기술적 세부 사항
반환 값: | 제공된 패턴과 일치하는 문자열을 포함하는 배열을 반환합니다. |
---|---|
PHP 버전: | 4+ |
❮ PHP RegExp 참조