Read multiple files and combine into one array
<p>I am quite new to PHP so this could be somewhere already answered.  However, I just could not find similar answer to my problem so here it goes: <br></p>

<p>I have a template file called "frozen.txt"  This file contains the list of frozen item numbers.its conents look like</p>

<hr>

<p>23476<br>
23829<br>
26974<br></p>

<hr>

<p>I also have around 20 files representing daily sales data: "frozen-4-1.txt", "frozen-4-2.txt", "frozen-4-3.txt" etc.  Each txt file contains 3 columns separated by ";" .  The first column is exactly the same of "frozen.txt" .  The 2nd column representing inventory number in the unit of "Each" and the 3rd column representing inventory number in the unit of "Box".  For example, "frozen-4-1.txt" would look like:</p>

<hr>

<p>23476;30;3<br>
23829;100;10<br>
26974;50;5<br></p>

<hr>

<p>"frozen-4-2.txt" look like</p>

<hr>

<p>23476; 20; 2<br>
23829; 90; 9<br>
26974; 40; 4<br></p>

<hr>

<p>"frozen-4-3.txt" look like</p>

<hr>

<p>23476; 10; 1<br>
23829; 60; 6<br>
26974; 20; 2<br></p>

<hr>

<p>Now I want to creat two new files called "outputeach.dat" and "outputbox.dat" This files use "frozen.txt" as its first column, then use daily data txt file's 2nd column and 3rd column as their new columns, respectively.(separated by ";")  Therefore, "outputeach.dat" would look like:</p>

<hr>

<p>23476;30;20;10<br>
23829;100;90;60<br>
26974:50;40;20<br></p>

<hr>

<p>and "outputbox.dat" looks like</p>

<hr>

<p>23476;3;2;1<br>
23829;10;9;6<br>
26974:5;4;2<br></p>

<hr>

<p>Here is my code trying to achieve this, but I am stuck at the end of the program</p>

<hr>

<pre><code>&lt;?php
include('path.php');
$space = "\r\n"; // For NewLine ...
$frzlist = array();
$readfrz = fopen("C:/purchase/dailydata/frozen.txt", "r");
while (!feof($readfrz)) {
$foo2 = fgets($readfrz);
$trufoo2 = trim( preg_replace( '/\s+/', ' ', $foo2 ) ); // get rid of new line in $foo2
$frzlist[] = $trufoo2; // read all the frozen item list into array $frzlist 
}
fclose($readfrz);
if ($handle = opendir(BASE_PATH)){
while (false !== ($file = readdir($handle)))
{
if ($file == "." || $file == ".."){}else
{
if(!strstr($file,"txt"))
{
continue; //Skip as file is not txt format
}
$s = explode("-",$file);
$prefix = $s[0];
$prefix1 = $s[1];
$prefix2 = $s[2];
//echo $prefix . " ";   // representing catogory
//echo $prefix1 . " ";  // representing month
//echo $prefix2 . " ";  // representing day
}

}
}
for($i=1 ; $i&lt;32; $i++){  //loop through one month data
$days = $prefix1 . "-" . $i ;
$file1 = BASE_PATH . $prefix . "-" . $prefix1 . "-" . $i . ".txt" ;
//echo $file1 . "\n";
//echo $days . "\n";
if (file_exists($file1)) {
$fileopen1 = fopen($file1,"r"); 
while (!feof($fileopen1)) {
$foo = fgets($fileopen1);
$members1[] = $foo; // read all the  contents into array $members1
}
$outputfrzpri = array();
$outputfrzsec = array();
if($prefix = "frozen"){
foreach ($members1 as $x1){
$pieces1 = explode(";", $x1); 

CODE needs help here
CODE needs help here
}

}
}   
} 
?&gt;
</code></pre>

<hr>

<p>Your advices is much appreciated</p>
