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 !
[email protected] Geek Xiaojun , Original article , B Station technology sharing
Personal blog : cnblogs.com
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 "
