...
数组处理,计算ng数量
本帖最后由 lazygc520 于 2015-05-12 22:26:04 编辑
array(6) {
[0]=>
string(62) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020.csv"
[1]=>
string(64) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_1.csv"
[2]=>
string(64) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_2.csv"
[3]=>
string(64) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_3.csv"
[4]=>
string(64) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_4.csv"
[5]=>
string(65) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_NG.csv"
}
已知数组a的形式,如果把7020开头的文件看作一个文件,求得这样的结果:ts407,bed410-500a1,5306,ng对应数量为1.这要怎么求?
------解决思路----------------------
$arr=array(
"../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020.csv",
"../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_1.csv",
"../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_2.csv",
"../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_3.csv",
"../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_4.csv",
"../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7020_NG.csv",
"../../dat/DIG/TestFunction/TS407/BED410-500A1/5306/NG/7021_NG.csv",//添加测试
);
foreach($arr as $v){
$tmp=explode('/',$v);
$lastfile=array_pop($tmp);
preg_match('/^(\d+)(\.
------解决思路----------------------
\_)/',$lastfile,$m);
$arr_file[]=$m[1];
}
$count=count(array_unique($arr_file));
echo $count;//2
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
相关文章
相关视频
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论