This code works almost perfectly. I have two csv files which I am building into arrays and then merging the arrays to contain the relevant information. The first contains part numbers, short description, and spc(category). The second contains Part numbers and amount available.
The idea is to match merge this information based on the part number and the sort the information and display it based on spc(category).
After testing out the readouts of each array, the problem seems to occur at STEP 4 and further compounds at STEP 5.
There are about 70,000 records. The majority of these are merged and displayed properly, they look like this:
[#10-CH-L/W] => Array
(
[0] => 362.00
[1] => HIGH COLLAR LOCK WASHER
[2] => NUTBLT
)
but at STEP 4, there are descriptions that get entered into their own array like this: (these should be in the [1] spot for an associated part)
[5872] => LINCOLN ADAPTOR 90-DEG 1/8 X 1/8
[5873] => MILW CYL H SERIES SPECIAL 8 X 16
[5874] => MILW CYL NEENAH # 55-40-6080-7
[5875] => MILW CYL L&S #DS001268 2 X 10
[5876] => CONTINENTAL PART SPOOL F1 V*50M
And at Step 5, further arrays are created from spcs like this: (these should be in the [2] spot for an associated part)
[11360] => NRGFIT
[11361] => NRGFIT
[11362] => NRGFIT
[11363] => LINLUB
[11364] => CHDPRT
From looking at the data in the csvs, the data seems to be consistant. The records where the problem occurs DO have part numbers that exist on BOTH documents. Is this an issue with the array_merge_recursive function? Do I need to look harder at the data? This is so close to being perfect!
<?php
$file1 = fopen('inventory/MasterInfoRows.csv', 'r');
$file2 = fopen('inventory/ItemLocationRows.csv', 'r');
$line = array();
$work = array();
//create arrays for part number, description, and spc from Masterinforows.csv
while (($line = fgetcsv($file1)) !== FALSE){
list($part, $desc, $spc) = $line;
$test1[] = $part;
$test2[] = $desc;
$test3[] = $spc;
}
//create arrays for part number and available amount from itemlocationrows.csv
while (($work= fgetcsv($file2, 1000)) !== FALSE) {
list($match, , , , , , , , $available) = $work;
$parts[] = $match;
$amounts[] = $available;
}
// STEP 1 combine ItemLocationRows CSV part numbers with associated amounts
$results = array_combine($parts, $amounts);
// STEP 2 combine MasterInfoRows part numbers with short descriptions
$master = array_combine($test1, $test2);
// STEP 3 combine MasterInfoRows part numbers with SPC
$master2 = array_combine($test1, $test3);
// STEP 4 combine itemlocation row part numbers and amount with Masterinfo Row part numbers short descriptions (about 6,000/70,000 records do not merge properly)
$alldata = array_merge_recursive($results, $master);
// STEP 5 combine itemlocationrow part numbers, amounts, and spc with MasterInfoRows part numbers and short descriptions (additional 5,000 extraneous spc values in array)
$success = array_merge_recursive($alldata, $master2);
//search through final array for records containing a specific spc in the array and return associated data
function searchForId($id, $array) {
$keyarray = array();
foreach ($array as $key => $val) {
if (isset($val[2]) && $val[2] === $id) {
array_push( $keyarray, $key);
echo "<tr><td>$key</td><td>$val[1]</td><td>$val[0]</td></tr>";
}
}
return $keyarray;
}
?>
edit A possible clue: itemlocationrows contains: 75,300 Records, whereas masterlocationrows contains 70,144