时间:2021-07-01 10:21:17 帮助过:11人阅读
$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);
$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);
通过什么区分,- 符号么?
$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);//可以得到两个分开不同类型的结果啊