数组处理,计算ng数量
本帖最后由 lazygc520 于 2015-05-12 22:26:04 编辑
<br />array(6) {<br /> [0]=><br /> string(62) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020.csv"<br /> [1]=><br /> string(64) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_1.csv"<br /> [2]=><br /> string(64) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_2.csv"<br /> [3]=><br /> string(64) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_3.csv"<br /> [4]=><br /> string(64) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_4.csv"<br /> [5]=><br /> string(65) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_NG.csv"<br />}<br />
Copy after login
已知数组a的形式,如果把7020开头的文件看作一个文件,求得这样的结果:ts407,bed410-500a1,5306,ng对应数量为1.这要怎么求?
------解决思路----------------------<br />$arr=array(<br /> "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020.csv",<br /> "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_1.csv",<br /> "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_2.csv",<br /> "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_3.csv",<br /> "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_4.csv",<br /> "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_NG.csv",<br /> "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7021_NG.csv",//添加测试<br />);<br />foreach($arr as $v){<br /> $tmp=explode('/',$v);<br /> $lastfile=array_pop($tmp);<br /> preg_match('/^(\d+)(\.<br><font color='#FF8000'>------解决思路----------------------</font><br>\_)/',$lastfile,$m);<br /> $arr_file[]=$m[1];<br />}<br />$count=count(array_unique($arr_file));<br />echo $count;//2<br />
Copy after login