当前位置:Gxlcms > PHP教程 > 数组处理,计算ng数量,该如何处理

数组处理,计算ng数量,该如何处理

时间:2021-07-01 10:21:17 帮助过:2人阅读

数组处理,计算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

人气教程排行