php - Structure CSV into Object/Arrays -


i using code import basic csv in each row represents invoice. these invoices grouped 1 of columns , json_encode produce json parent/child hierarchy. how go doing this?

csv

 id      cardcode    sum            amount       165     benv5271    100            100   026     benv5635    509.85         287.33  9025    benv5635    509.85         222.52   

php

if (($handle = fopen('upload/ben-new.csv', "r")) === false) {     die('error opening file');  }  $headers = fgetcsv($handle, 1024, ',');  $cardcodes = array();   while ($row = fgetcsv($handle, 1024, ",")) {     $cardcodes[] = array_combine($headers, $row); } fclose($handle); 

json (goal)

 [ {  "cardcode":"benv5271",   "payment_sum": "100.00"  "details": [ {     "docnum": "165",     "invpayamnt": "100.00",     "pmntdate": "2012-03-29"   } ],  }, {  "cardcode": "benv5635",  "payment_sum": "509.85"  "details": [ {      "docnum": "026"        "invpayamnt": "287.33",      "pmntdate": "2012-03-29"    }, {      "docnum": "025",      "invpayamnt": "222.52",      "pmntdate": "2012-03-29"    } ], } ] 

for each $row,

@$cardcodes[$row[1]]['payment_sum'] += $row[3]; @$cardcodes[$row[1]]['details'][] = array(     'docnum' => $row[0],     'invpayamnt' => $row[3],     'pmntdate' => $row[4?], ); 

not same format indexed, , for x in y loops in js.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -