CSV aus mehrdimensionalem Array mit fputcsv erstellen

Ich versuche ein mehrdimensionales Array in eine CSV-Datei zu bekommen. Daten im Array lauten wie folgt:

Array
(
 [0] => Array
    (
        [product_id] => 1111
        [name] => Alcatel One Touch Idol 2
        [keyword] => alcatel-one-touch-idol-2
        [options] => Array
            (
                [0] => Array
                    (
                        [price] => 54.0000
                    )

                [1] => Array
                    (
                        [price] => 42.0000
                    )

                [2] => Array
                    (
                        [price] => 10.0000
                    )

                [3] => Array
                    (
                        [price] => 
                    )

                [4] => Array
                    (
                        [price] => 
                    )

                [5] => Array
                    (
                        [price] => 
                    )

                [6] => Array
                    (
                        [price] => 
                    )

                [7] => Array
                    (
                        [price] => 
                    )

                [8] => Array
                    (
                        [price] => 
                    )

                [9] => Array
                    (
                        [price] => 
                    )

            )

    )

[1] => Array
    (...... etc)

Ich erhalte alle Daten der obersten Ebene, aber sobald es das Options-Array erreicht, erhalte ichArray to string conversion Fehler. Ich habe also zwei Probleme. Zuerst muss ich sehen, warum ich diesen Fehler erhalte, und dann muss ich alle diese Informationen in einer Zeile pro Produkt eingeben.

So weit ich habe dies, um das Array in eine CSV zu analysieren:

$output = fopen("php://output",'w') or die("Can't open php://output");
            header("Content-Type:application/csv"); 
            header("Content-  Disposition:attachment;filename=product_catalog.csv"); 
            $first_line = explode(",", $first_line);
            fputcsv($output, $first_line);
            foreach($csv as $file) {
                fputcsv($output, $file);
            }
            fclose($output) or die("Can't close php://output");

Wenn mir jemand helfen könnte, würde ich das wirklich zu schätzen wissen. Grüße

Antworten auf die Frage(4)

Ihre Antwort auf die Frage