<?php /** * Created by PhpStorm. * User: Ollydebug * Date: 2015/11/13 * Time: 22:55 */ //阉割版preg_filter //preg_grep函数只会去做匹配的操作,不做替换 $pattern = '/[0-9]/'; $subject = array('weuy','r3ui','76as83','s','0ck9'); $arr = preg_grep($pattern,$subject); show($arr); function show($var){ if(empty($var)){ echo 'null'; }elseif(is_array($var)||is_object($var)){ // array,object echo '<pre class="brush:php;toolbar:false">'; print_r($var); echo ''; }else{ //string,int,float echo $var; } } ?>
以上就是(PHP)正则表达式-preg_grep函数用法的内容,更多相关内容请关注PHP中文网(www.php.cn)!