<?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; } } ?>
The above is the content of (PHP) regular expression-preg_grep function usage. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!