This question already has an answer here:
This is my sample.json file
"general": {
"option_name" : "option_name",
"filter_name" : "filter name"
}
and I want to update the value using key
$string = "general.filter_name";
$updateContent = "new filtername";
$langArray = explode('.',$string);
print_r($langArray);
/*Array
(
[0] => general
[1] => filter_name
) */
$file='assets/sample.json';
$jsonString = file_get_contents($file);
$data = json_decode($jsonString, true);
**$data['general']['filter_name'] = $updateContent; **
$newJsonString = json_encode($data);
file_put_contents($file, $newJsonString);
Here I want to assign Array
[0] => general
[1] => filter_name
should be
$data['general']['filter_name']
How to define array like this? Thanks
</div>