M
M
MrJobs2020-04-26 12:43:23
PHP
MrJobs, 2020-04-26 12:43:23

JSON iteration and writing?

Hello uv. connoisseurs.
I can’t think of a story I’m collecting
the necessary data from a JSON file into an array
I need to collect its data for each key and write it to a separate file
Everything is fine, the files have been collected, created, but the entire array is being written, not this key
Sample code below, please help, pzh

$struct = json_decode(file_get_contents("..."), TRUE);
        $assoc = [];
        foreach ($struct['Exmpl'] as $key => $value){
            $assoc[$key] = $value['Exmpl'];

            $exmpl_file = 'exmpl/'.$key.'.json';

            if (file_exists($exmpl_file)) {
                // записываем 
                $file = file_get_contents($exmpl_file );//открываем файл
                $taskList = json_decode($file,TRUE);//декодируем в JSON
                $taskListIn[] = array('date' => $time, 'exmpl' => $key['exmpl']);
                file_put_contents($exmpl_file,json_encode($taskListIn),FILE_APPEND);//записываем
            } else {
                $handle = fopen($exmpl_file, "w");//если нет файла - соаздаем
            }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question