Array Processing, calculate the number of ng. this post is Last edited by lazygc520 from 2015-05-1222:26:04 array (6) & nbsp ;{& nbsp; & nbsp; [0] & gt; & nbsp; string (62) & nbsp ;.... datDIGTestFunctionTS407BED4 array processing, calculate the number of ng
This post was last edited by lazygc520 at 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"
}
Known array a form, if the file starting with 7020 as a file, obtain the result: ts407, bed410-500a1, 5306, ng corresponds to the number of 1. how can this?
------ Solution ----------------------
$ 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", // add test
);
Foreach ($ arr as $ v ){
$ Tmp = explode ('/', $ v );
$ Lastfile = array_pop ($ tmp );
Preg_match ('/^ (\ d + )(\.
------ Solution ----------------------
\ _)/', $ Lastfile, $ m );
$ Arr_file [] = $ m [1];
}
$ Count = count (array_unique ($ arr_file ));
Echo $ count; // 2