array preg_grep ( string $pattern, array $input [, int $flags] );
返回由与给定模式匹配的输入数组元素组成的数组。
如果将flag设置为PREG_GREP_INVERT,则此函数返回输入数组中与给定模式不匹配的元素。
返回使用输入数组中的键索引的数组。
<?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]; ?>
这将产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/php/php-preg-grep.html
来源:LearnFk无涯教程网
Found food is pastaFound food is
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)