I'm trying to take the contents of two CSVs, extract only certain pieces of information, and have them stored in an array of associative arrays. Ultimately I'm dealing with exports of PC information, and am trying to create a single array of PC Names, each one being itself an associative array of attributes.
It seems to be working fine at first, however when I try to add attributes from the second source I'm seeing the attributes be added to a new array with the same name, rather than adding the attribute to the existing array.
The first set (works as expected):
if($_FILES['panda']['error'] == 0){
$pandaExt = strtolower(end(explode('.', $_FILES['panda']['name'])));
$pandaTmpName = $_FILES['panda']['tmp_name'];
if($pandaExt === 'csv'){
$pandaHandle = @fopen($pandaTmpName, "r");
if ($pandaHandle) {
fgetcsv($pandaHandle, 0, "\t");
while (($row = fgetcsv($pandaHandle, 0, "\t")) !== false) {
switch ($row[1]) {
case "Server":
$servers[$row[2]]["Name"] = $row[2];
break;
default:
$computers[$row[2]]["Name"] = $row[2];
$computers[$row[2]]["Type"] = $row[1];
$computers[$row[2]]["AV"] = $row[20];
$computers[$row[2]]["OS"] = $row[14];
$computers[$row[2]]["LastUser"] = $row[40];
$computers[$row[2]]["LastSeen"] = $row[12];
break;
}
}
fclose($pandaHandle);
}
}
}
The second export (creates duplicate arrays inside of $computers):
if($_FILES['ncentral']['error'] == 0){
$ncentralExt = strtolower(end(explode('.', $_FILES['ncentral']['name'])));
$ncentralTmpName = $_FILES['ncentral']['tmp_name'];
if($ncentralExt === 'csv'){
$ncentralHandle = @fopen($ncentralTmpName, "r");
if ($ncentralHandle) {
for($i=0;$i<7;$i++)
{
fgetcsv($ncentralHandle, 0, ",");
}
while (($row = fgetcsv($ncentralHandle, 0, ",")) !== false) {
if($row[1] == "Application" && $row[2] == "Display Name")
{
array_push($applications[$row[3]],$row[0]);
}
if($row[1] == "BIOS" && $row[2] == "Serial number")
{
$computers[$row[0]]["Serial"] = $row[3];
}
}
fclose($ncentralHandle);
}
}
}
The end result is the $computers array outputting:
[CADUSER-PC] => Array
(
[Name] => CADUSER-PC
[Type] => Workstation
[AV] => data
[OS] => data
[LastUser] => data
[LastSeen] => data
)
[CADUSER-PC] => Array
(
[Serial] => data
)
I can't get my head around why it doesn't just add the Serial attribute to the original array. Any ideas?