Home > Backend Development > PHP Tutorial > 求一个匹配到这个数组所有成员的正则

求一个匹配到这个数组所有成员的正则

WBOY
Release: 2016-06-23 14:00:47
Original
1194 people have browsed it

array(100-10, -50,200-20, 300-30, -30)求一个匹配到这个数组所有成员的正则


回复讨论(解决方案)

$arr = array('100-10', '-50','200-20', '300-30', '-30');	$b = array();	foreach ($arr as $value) {		if(preg_match("/[\d-]+/", $value,$match)){			array_push($b, $match);		}	}	var_dump($b);
Copy after login
Copy after login

$arr = array('100-10', '-50','200-20', '300-30', '-30');	$b = array();	foreach ($arr as $value) {		if(preg_match("/[\d-]+/", $value,$match)){			array_push($b, $match);		}	}	var_dump($b);
Copy after login
Copy after login


谢谢 但不是我想要的
我的需要 是这样的
$arr=array('200-30','lsflsdf','全场5折','50-10','100-30','-50','1000-100');
我需要把有'200-30'或'-30'这种类型的和其它类型的分开 分别赋给不同的变量

通过什么区分,- 符号么?

$arr = array('100-10', 'lsflsdf','全场5折','-50','200-20', '300-30', '-30','1000-100');	$a = array();//存放其他类型	$b = array();//存放'200-30'或'-30'这种类型	foreach ($arr as $value) {		if(preg_match("/^[\d-]+/", $value,$match)){			array_push($b, $match);		}else{			array_push($a, $value);		}	}	var_dump($a,$b);//可以得到两个分开不同类型的结果啊
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template