编程知识 cdmana.com

PHP regular expression core technology full details section 7 array elements regular matching

author : Geek Xiaojun One focuses on web technology 80 after
I don't have to spell smart people , I just need to spell those lazy people I will certainly surpass most people !
CSDN@ Geek Xiaojun , Original article , B Station technology sharing
Personal blog : cnblogs.com

 Insert picture description here

PHP Regular match array elements


preg_grep( Parameters ..) Returns the array entry of the matching pattern , Array elements that meet the conditions of regular expression in an array , And the return data type is array !
parameter list :
Parameters 1: Regular expressions
Parameters 2: Detecting matching arrays The index array Associative array It's all right !
Parameters 3: Set the result to an array of regular mismatched elements

Case code 1:

// Customize an array 
$array=array("23.32","22","12.009","23.43.43","-100","zhangsan");

// Matches numbers with two decimal points 
$pattern="/^(\d+)?\.\d+\.\d+$/";
$result1=preg_grep($pattern, $array);
show($result1);

// Match the numbers ,  Including negative numbers 
$pattern="/-?\d/";
$result1=preg_grep($pattern, $array);
show($result1);

Case code 2:

// Customize an array 
$array=array("23.32","22","12.009","23.43.43","-100","zhangsan");
$pattern="/^(\d)+?\.(\d)+$/";
$result=preg_grep($pattern, $array);
show($result);
" give the thumbs-up " " Comment on " " Collection "

Everyone's support is my driving force to stick to it !

If any of the above is inaccurate , Welcome below Leave a message to point out 、 Or you have a better idea , Welcome to exchange and study together
Focus on Geek Xiaojun WeChat official account Irregular update free Technical dry cargo


版权声明
本文为[Geeker Jun]所创,转载请带上原文链接,感谢

Scroll to Top