Home >Backend Development >PHP Tutorial > php根据条件排除,该如何解决

php根据条件排除,该如何解决

WBOY
WBOYOriginal
2016-06-13 12:29:49825browse

php根据条件排除

$a = "'你好(39)','你好啊(60)','他好(52)','他好啊(23)','我好(80)','我好啊(99)'";


怎么把$a里括号中小于50的排除掉'你好(39)',把红色的整体排除掉

麻烦知道的大哥直接给完整代码,谢谢了拖沓一点,应该用正则可以直接实现吧


$a = "'你好(39)','你好啊(60)','他好(52)','他好啊(23)','我好(80)','我好啊(99)'";
$arr = explode('\',\'', trim($a, '\''));
$newArr = array();
foreach ($arr as &$value) {
if (preg_match('/[\d]+/', $value, $match)) {
if (isset($match[0])) {
if ($match[0] > 50) {
$newArr[] = '\''.$value.'\'';
}
}
}
}

echo '"'.implode(',',$newArr).'"';

Statement:
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