preg_grep 返回匹配模式的数组条目

array preg_grep('正则',array,0)

//返回匹配到数组形式,内容为包含元数组下表的数组

array preg_grep('正则',array,PREG_GREP_INVERT)

//返回不在匹配内容的数组形式,内容为包含元数组下表的数组

例:

$subjects = array

"Mechanical Engineering", "Medicine", 

"Social Science", "Agriculture", 

"Commercial Science", "Politics" 

); 

//匹配所有仅由有一个单词组成的科目名 

$alonewords = preg_grep("/^[a-z]*$/i", $subjects);


 

原文地址:https://www.cnblogs.com/xiongwei89/p/2993010.html