Записываю массив в json
Вот такая запись
$jsonFileUser[$_SESSION['email']]["orders"][] = $content;
print_r($jsonFileUser[$_SESSION['email']]["orders"]);
выдает:
Array ( [212] => Array ( [id] => 212 [name_order] => Получение разрешения на строительство [date] => 23.10.18 [order_id] => 1 [step] => 2 [answer_status] => received [performed] => true [inquiry] => Array ( [object_address] => [cad_number] => [name_obejct] => [floors] => [commissioning] => [electric] => [water] => [firefighting] => [consumption] => firefighting_max [directions_of_gas] => ) ) [213] => Array ( [name_order] => Получение разрешения на строительство [date] => 24.10.18 [order_id] => 1 [step] => 2 [answer_status] => received [performed] => true [inquiry] => Array ( [object_address] => asd [cad_number] => 12:12:3123123:123 [name_obejct] => BoilerRoom [floors] => 123 [commissioning] => 0333-03-12 [electric] => MoreHundredFifty [water] => waterSupply [firefighting] => 123 [consumption] => firefighting_max [directions_of_gas] => Горячее водоснабжение, Отопление, ) ) )
Если вкратце, то получает значение из того что было, а была 1 запись (212), записывает новое - 213, после перевода в json все остается так же, только меняется формат.
НО
Когда я записываю через
file_put_contents($fileUser,$contentJson);
Он записывает уже 2 раза, то есть получается так что записывается 212, 213, 214, хотя 214 там быть не должно.
{
"email@mail.ru":{
"name":"\u0412\u0438\u043a\u0442\u043e\u0440",
"secname":"\u041a\u043e\u0442\u043e\u0432",
"order":"true",
"orders":{
"212":{
"id":212,
"name_order":"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e",
"date":"23.10.18",
"order_id":"1",
"step":"2",
"answer_status":"received",
"performed":"true",
"inquiry":{
"object_address":null,
"cad_number":null,
"name_obejct":null,
"floors":null,
"commissioning":null,
"electric":null,
"water":null,
"firefighting":null,
"consumption":"firefighting_max",
"directions_of_gas":""
}
},
"213":{
"name_order":"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e",
"date":"24.10.18",
"order_id":"1",
"step":"2",
"answer_status":"received",
"performed":"true",
"inquiry":{
"object_address":"asd",
"cad_number":"12:12:3123123:123",
"name_obejct":"BoilerRoom",
"floors":"123",
"commissioning":"0333-03-12",
"electric":"MoreHundredFifty",
"water":"waterSupply",
"firefighting":"123",
"consumption":"firefighting_max",
"directions_of_gas":"\u0413\u043e\u0440\u044f\u0447\u0435\u0435 \u0432\u043e\u0434\u043e\u0441\u043d\u0430\u0431\u0436\u0435\u043d\u0438\u0435, \u041e\u0442\u043e\u043f\u043b\u0435\u043d\u0438\u0435, "
}
}
}
}
}
Так должно быть в файле, на деле получается так:
{
"email@mail.ru":{
"name":"\u0412\u0438\u043a\u0442\u043e\u0440",
"secname":"\u041a\u043e\u0442\u043e\u0432",
"order":"true",
"orders":{
"212":{
"id":212,
"name_order":"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e",
"date":"23.10.18",
"order_id":"1",
"step":"2",
"answer_status":"received",
"performed":"true",
"inquiry":{
"object_address":null,
"cad_number":null,
"name_obejct":null,
"floors":null,
"commissioning":null,
"electric":null,
"water":null,
"firefighting":null,
"consumption":"firefighting_max",
"directions_of_gas":""
}
},
"213":{
"name_order":"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e",
"date":"24.10.18",
"order_id":"1",
"step":"2",
"answer_status":"received",
"performed":"true",
"inquiry":{
"object_address":"asd",
"cad_number":"12:12:3123123:123",
"name_obejct":"BoilerRoom",
"floors":"123",
"commissioning":"0333-03-12",
"electric":"MoreHundredFifty",
"water":"waterSupply",
"firefighting":"123",
"consumption":"firefighting_max",
"directions_of_gas":"\u0413\u043e\u0440\u044f\u0447\u0435\u0435 \u0432\u043e\u0434\u043e\u0441\u043d\u0430\u0431\u0436\u0435\u043d\u0438\u0435, \u041e\u0442\u043e\u043f\u043b\u0435\u043d\u0438\u0435, "
}
},
"214":{
"name_order":"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e",
"date":"24.10.18",
"order_id":"1",
"step":"2",
"answer_status":"received",
"performed":"true",
"inquiry":{
"object_address":"asd",
"cad_number":"12:12:3123123:123",
"name_obejct":"BoilerRoom",
"floors":"123",
"commissioning":"0333-03-12",
"electric":"MoreHundredFifty",
"water":"waterSupply",
"firefighting":"123",
"consumption":"firefighting_max",
"directions_of_gas":"\u0413\u043e\u0440\u044f\u0447\u0435\u0435 \u0432\u043e\u0434\u043e\u0441\u043d\u0430\u0431\u0436\u0435\u043d\u0438\u0435, \u041e\u0442\u043e\u043f\u043b\u0435\u043d\u0438\u0435, "
}
}
}
}
}