0

How can i generate csv file using this kind of data. key value also have array which is not clear to me how I can get this data and save in CSV.

    echo "<pre>";
    print_r($data[result][items]);
    echo "</pre>";

Printing on browser is this.

    Array (
    [0] => Array (
        [item] => Array
            (
                [doc_id] => bc500548
                [doc_type] => void
                [fields] => Array
                    (
                        [dc_creator] => Array
                            (
                                [0] => onbekend
                                [1] => Pictura
                            )

                        [dc_description] => Array
                            (
                                [0] => Spectrum
                            )

                        [dc_format] => Array
                            (
                                [0] => 1945
                            )
                    )

            )

    )

    [1] => Array (
        [item] => Array (
            [doc_id] => bc500549
            [doc_type] => void2
            [fields] => Array
                (
                    [dc_creator] => Array
                        (
                            [0] => onbekend2
                            [1] => Pictura2
                        )

                    [dc_description] => Array
                        (
                            [0] => Spectrum2
                        )

                    [dc_format] => Array
                        (
                            [0] => 1946
                        )
                )

        )

)

I dont understand how to get this values and save in csv file, can anybody help me about that?

  • 1
    In order to get the data you need to access `$data['result']['items']` - there are mega tons of examples out there – B001ᛦ Jun 27 '19 at 10:58
  • I put it question here because "key" has another array and thats i dont get it. – NostroDev Jun 27 '19 at 11:03
  • try to echo `$data['result']['items'][0]['item']['doc_id']` – B001ᛦ Jun 27 '19 at 11:04
  • yeah that i tried before, but can you tell me how can i get data [dc_creator] both values with comma separator ? – NostroDev Jun 27 '19 at 11:17
  • _...both values with comma separator..._ implode() – B001ᛦ Jun 27 '19 at 11:28
  • you know anything about writing csv file with the key name, file have 50 columns but if one record array have just two values one is on 5th column and second is on 15th. is that possible to find that column and save data in right column. – NostroDev Jun 27 '19 at 14:16
  • https://stackoverflow.com/questions/15501463/creating-csv-file-with-php - Start your own research now - I'm out – B001ᛦ Jun 27 '19 at 14:18

0 Answers0