Array Processing, calculating the number of ng, how to deal with it

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.