Heim >Backend-Entwicklung >PHP-Tutorial >数组处理,计算ng数量
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"}
如果是这样呢?
foreach (glob($datapath."/NG/*.csv") as $filename) { preg_match('/.+\/(\d+)/',$filename,$match); echo $value_lotno.'=>'.$match[1].'<br />'; }
5106=>80015127=>72075127=>72075306=>70205306=>70205306=>70205306=>70205306=>70205306=>70205309=>71735309=>71735310=>71025310=>71025310=>72535310=>72535310=>74345310=>74345310=>74435310=>74435310=>75085310=>75085310=>75735310=>7573
array('5106=>8001','5127=>7207','5306=>7020','5309=>7173','5310=>7102','5310=>7253','5310=>7434','5310=>7443','5310=>7508','5310=>7573');
$arr=array( '5106=>8001', '5127=>7207', '5127=>7207', '5306=>7020', '5306=>7020', '5306=>7020', '5306=>7020', '5306=>7020', '5306=>7020', '5309=>7173', '5309=>7173', '5310=>7102', '5310=>7102', '5310=>7253', '5310=>7253', '5310=>7434', '5310=>7434', '5310=>7443', '5310=>7443', '5310=>7508', '5310=>7508', '5310=>7573', '5310=>7573',);echo "<pre class="brush:php;toolbar:false">";print_r(array_values(array_unique($arr)));echo "";/*Array( [0] => 5106=>8001 [1] => 5127=>7207 [2] => 5306=>7020 [3] => 5309=>7173 [4] => 5310=>7102 [5] => 5310=>7253 [6] => 5310=>7434 [7] => 5310=>7443 [8] => 5310=>7508 [9] => 5310=>7573)*/
$arr=array( '5106=>8001', '5127=>7207', '5127=>7207', '5306=>7020', '5306=>7020', '5306=>7020', '5306=>7020', '5306=>7020', '5306=>7020', '5309=>7173', '5309=>7173', '5310=>7102', '5310=>7102', '5310=>7253', '5310=>7253', '5310=>7434', '5310=>7434', '5310=>7443', '5310=>7443', '5310=>7508', '5310=>7508', '5310=>7573', '5310=>7573',);echo "<pre class="brush:php;toolbar:false">";print_r(array_values(array_unique($arr)));echo "";/*Array( [0] => 5106=>8001 [1] => 5127=>7207 [2] => 5306=>7020 [3] => 5309=>7173 [4] => 5310=>7102 [5] => 5310=>7253 [6] => 5310=>7434 [7] => 5310=>7443 [8] => 5310=>7508 [9] => 5310=>7573)*/
你不都循环出来了吗.....
echo $value_lotno.'=>'.$match[1].'
';
下面加上
$arr[]=$value_lotno.'=>'.$match[1];
这样就行了
你不都循环出来了吗.....
echo $value_lotno.'=>'.$match[1].'
';
下面加上
$arr[]=$value_lotno.'=>'.$match[1];
这样就行了
举个例子来看!
举个例子来看!
$datapath = '../../dat/DIG/TestFunction/'.$machine.'/'.$value_type.'/'.$value_lotno;//已求得var_dump(glob($datapath.'/NG/*.*', GLOB_BRACE));
array(1) { [0]=> string(62) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5106/NG/8001.csv"}array(2) { [0]=> string(62) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5127/NG/7207.csv" [1]=> string(65) "../../dat/DIG/TestFunction/TS407/BED410-500A1/5127/NG/7207_NG.csv"}array(0) {}array(0) {}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"}
$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
$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
唉,二维你就判断一下就行了嘛
$all=array(array( "../../dat/DIG/TestFunction/TS407/BED410-500A1/5106/NG/8001.csv"),array( "../../dat/DIG/TestFunction/TS407/BED410-500A1/5127/NG/7207.csv", "../../dat/DIG/TestFunction/TS407/BED410-500A1/5127/NG/7207_NG.csv",),array(),array(),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($all as $arr){ if(!$arr){ continue; } 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;//4
唉,二维你就判断一下就行了嘛
$all=array(array( "../../dat/DIG/TestFunction/TS407/BED410-500A1/5106/NG/8001.csv"),array( "../../dat/DIG/TestFunction/TS407/BED410-500A1/5127/NG/7207.csv", "../../dat/DIG/TestFunction/TS407/BED410-500A1/5127/NG/7207_NG.csv",),array(),array(),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($all as $arr){ if(!$arr){ continue; } 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;//4
我是醉了,能一次说完么,哥
$count=count(array_unique($arr_file));
改为
$new=array_count_values($arr_file);