euphoric Posted December 21, 2011 Report Share Posted December 21, 2011 (edited) Ir .csv fails ar saturu: "a","b","c" 1,2,3 4,5,6 Nepieciešāma funkcija kas atgriež šādu massīvu: array( 'a' => array(1, 4), 'b' => array(2, 5), 'c' => array(3, 6) ); Ir kādi jēdzīgi varianti? Paldies. Edited December 21, 2011 by euphoric Quote Link to comment Share on other sites More sharing options...
briedis Posted December 21, 2011 Report Share Posted December 21, 2011 http://php.net/manual/en/function.fgetcsv.php Quote Link to comment Share on other sites More sharing options...
euphoric Posted December 21, 2011 Author Report Share Posted December 21, 2011 http://php.net/manua...ion.fgetcsv.php Tik tālu nav problēmas... Quote Link to comment Share on other sites More sharing options...
briedis Posted December 21, 2011 Report Share Posted December 21, 2011 Kur tad ir? Quote Link to comment Share on other sites More sharing options...
euphoric Posted December 21, 2011 Author Report Share Posted December 21, 2011 Nevaru galā dabūt šādu masīva struktūru: array( 'a' => array(1, 4), 'b' => array(2, 5), 'c' => array(3, 6) ); Quote Link to comment Share on other sites More sharing options...
briedis Posted December 21, 2011 Report Share Posted December 21, 2011 (edited) Parādi, ko tu tur esi sarakstījis :) edit: sliktākajā gadījumā vari izmantot file() apvienojumā ar explode() Edited December 21, 2011 by briedis Quote Link to comment Share on other sites More sharing options...
Ugin Posted December 21, 2011 Report Share Posted December 21, 2011 (edited) function collectColsFromCsv(string $filename) { $row = 1; // this row is keys for array $result = null; if (($handle = fopen($filename, "r")) !== FALSE) { $keys = fgetcsv($handle, 1000, ","); $keyCount= count($keys); $row++; // going to rows with array valuess while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { for ($c=0; $c < $keyCount; $c++) { $result[$keys[$c]][]=$data[$c]; } } fclose($handle); } return $result; } Re kada bus funkcija. Sis uzdevums izskatas pec uzdevuma ko piedava risinat kompanija dyninno pie iestasanas pie viniem darba Edited December 22, 2011 by Ugin Quote Link to comment Share on other sites More sharing options...
Kaklz Posted December 22, 2011 Report Share Posted December 22, 2011 1) Nomaini $num pret $keyCount ;) 2) $row mainīgais netiek izmantots Quote Link to comment Share on other sites More sharing options...
Ugin Posted December 22, 2011 Report Share Posted December 22, 2011 šajai funkcijai vel daudz kas bija iekša tapec tie liekie mainingie palika. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.