पीएचपी preg_grep () समारोह
उदाहरण
एक सरणी से आइटम प्राप्त करें जो "पी" से शुरू होता है:
<?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. |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | दिए गए पैटर्न से मेल खाने वाली स्ट्रिंग वाली एक सरणी देता है |
---|---|
पीएचपी संस्करण: | 4+ |
❮ PHP RegExp संदर्भ