preg_grep() - 语法
array preg_grep ( string $pattern, array $input [, int $flags] );
返回由与给定模式匹配的输入数组元素组成的数组。
如果将flag设置为PREG_GREP_INVERT,则此函数返回输入数组中与给定模式不匹配的元素。
preg_grep() - 返回值
-
返回使用输入数组中的键索引的数组。
preg_grep() - 示例
php $foods=array("pasta", "steak", "fish", "potatoes"); //find elements beginning with "p", followed by one or more letters. $p_foods=preg_grep("/p(\w+)/", $foods); print "Found food is " . $p_foods[0]; print "Found food is " . $p_foods[1];?>
这将产生以下输出-
Found food is pastaFound food is
来源地址:https://blog.csdn.net/w116858389/article/details/132430059