mardi 7 juillet 2020

How to create a json file from chunks of data

i have a 5000 rows in the database and trying to get the data as chunks and create one json file that contain all the 5000 rows, my code

ManagerFacade::findAllAsChunks(function ($timeSignals) {
                    foreach ($timeSignals as $timeSignalIndex => $timeSignal) {
                        $InputFile = '{';
                        $InputFile .= '"v": ' . $timeSignal->v . ",";
                        $InputFile .= '"t": ' . $timeSignal->t;
                        $InputFile .= '}';
                        if($isLastChunk && !isset($timeSignals[$timeSignalIndex + 1])) {
                            $InputFile .= '';
                        } else {
                            $InputFile .= ',';
                        }
                        file_put_contents($filePath, $InputFile, FILE_APPEND);
                    }
                }
            );

i'm looking for a better way to create the json file without the need to concatenated, is their a way to just json_encode the $timeSignals arrays and put them in the file one after each other, without looping



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire