Answer the question
In order to leave comments, you need to log in
How to change data in JSON file using PHP?
There is a JSON file like this: {"name" : "value1"} .
Using PHP, I get the value of value1 , somehow change it (it doesn’t matter) and I want to push the already changed value of value1_new into JSON so that I get a file like: {"name" : "value1_new"} .
That is, if there was {"name" : "Ivan"} , so that it becomes {"name" : "Vasiliy"} after my manipulations.
PHP:
<?php
$json = file_get_contents('./json_file.json');
$json = json_decode($json, true);
$name = $json['name'];
// манипуляции с $name
// ...
// Например, было $name="Ivan", стало $name="Vasiliy"
// и тут нужно в JSON закинуть уже измененный $name
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question