2016-07-14 11 views
0

Ich weiß nicht, wie Sie dieses JSON-Array in eine CSV konvertieren.JSON Array in CSV mit Zeilennamen konvertieren?

[relatedProducts] => Array 
(
    [0] => 111001 
    [1] => 111002 
    [2] => 111007 
    [3] => 111021 
    [4] => 111022 
    [5] => 111024 
    [6] => 111027 
    [7] => 111121 
    [8] => 111122 
    [9] => 111127 
    [10] => 111128 
    [11] => 111141 
    [12] => 111142 
    [13] => 111144 
    [14] => 111147 
) 

Ich mag relatedProducts der Zeile Name sein und im Bereich unterhalb von relatedProducts sollte es sein „111001,111002,111007 .....“

relatedProducts 
111001,111002,111007 

Was ich versucht habe, ist etwas, dies wie:

foreach($array as $obj) 
{ 
    $related = $obj->relatedProducts; 
}; 
if (empty($firstLineKeys)) 
{ 
    $firstLineKeys = array_keys($relatedProducts); 
    fputcsv($f, $firstLineKeys, ';'); 
    $firstLineKeys = array_flip($firstLineKeys); 
} 
fputcsv($f, $relatedProducts, ';'); 
+0

Was mit falsch dein Code? Erhalten Sie einen Fehler? –

Antwort

0

Dies wird tun, was Sie fragen, mit den begrenzten Daten und Kontext zur Verfügung gestellt:

foreach ($array as $k => $v) 
{ 
    print("$k\n".implode(',', $v)."\n"); 
} 

Ausgänge

relatedProducts 111001,111002,111007,111021,111022,111024,111027,111121,111122,111127,111128,111141,111142,111144,111147