دالة 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