(PHP)正则表达式-preg_grep函数用法
程序员文章站
2022-03-30 16:15:10
...
<?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>'; print_r($var); echo '</pre>'; }else{ //string,int,float echo $var; } } ?>
以上就是(PHP)正则表达式-preg_grep函数用法的内容,更多相关内容请关注PHP中文网(www.php.cn)!
推荐阅读