I'm trying to add user to json , but every time it overwrites the string, and it turns out that there is one user . I correctly described what each line does? But why is it being overwritten?
$input = json_decode($_POST["phones"], true); //вот что в `input`-е если что. //$input = '[["5345", "345345", "123"], "Michael", "Podlevskykh"]'; $file = file_get_contents('jsn.json'); //получаем файл $output = json_decode($file,TRUE);//декодируем unset($file); // чистим переменную // потом добавим в JSON $output = [ 'user2' => [ 'first_name' => $input[1], 'last_name' => $input[2], 'phones' => [ 'phone_1' => $input[0][0], 'phone_2' => $input[0][1], 'phone_3' => $input[0][2] ] ] ]; file_put_contents('jsn.json',json_encode($output));//преобразуем в строку unset($output); //чистим
$output =this is clearly a replacement, not an addition - andreymalmege, but it merges two into one, but I need[ name, last, [phones...] ]@DanielProtopopov - Misha Podlevsky