Array with multiple Arrays from CSV PHP

z0mg0sh

New Member
I'm trying to learn PHP and so developing a PHP script that will read a CSV file and place it in a array with multiple arrays inside.The CSV is composed by this structureUSER,PRINTER,PAGES,COPIES,GRAYSCALE,DUPLEX001,001,1,2,G,D001,002,1,3,C,ND002,003,2,2,C,DSo far I've managed to create a PHP script that outputs the main Array with the "users" sub-array inside.Something like this\[code\]Array( ['user1']=>Array ( ['printer1']=>Array ( [PAGES]=>'1' ) ))\[/code\]This for multiple users, but i can't seem to multiply the printers inside the Users array.This is my code:\[code\]<?php$arrprint = array();$arrprinter = array();if (($handle = fopen("log-2013-04-03.csv", "r")) !== FALSE) { while (($data = http://stackoverflow.com/questions/15900946/fgetcsv($handle, 1000,",")) !== FALSE) { if (! isset($arrprint ["".$data[1].""]) ){ $arrprint ["'".$data[1]."'"] = $data[1]; if(! isset($arrprinter["".$data[4].""]) ) $arrprinter["'".$data[4]."'"] = ['Pages' => $data[2]]; } /*$arrprint ["'".$data[1]."'"] = [ "'".$data[4]."'" => ['NoPag' => $data[2]]];*/ $arrprint["'".$data[1]."'"] = $arrprinter; } print_r ($arrprint); fclose($handle);}\[/code\]What Am I doing wrong? Is there any loop missing from my code?
 
Top