So hello, I am working with json data and created a admin.php page thats adds data to the database . So before I took about the question I will show you my code. url.json
{
"minecraft" : [
{
"version" : "MC v1",
"url" : "http://www.google.com"
},
{
"version" : "MC v12",
"url" : "http://www.google.com"
}
]
}
admin.php code snippet
## Add MC to version
$Version = "MC " . strtolower($_POST["version"]);
## Insert Data To JSON file!!!!
$Data_Now = file_get_contents('url.json');
$json = json_decode($Data_Now, true);
$DataAppend = array(
"version" => $Version,
"url" => $_POST["url"]
);
$json[] = $DataAppend;
$final_data = json_encode($json);
if(file_put_contents('url.json', $final_data)) {
# Displays message here
}
So here is my Question As you see in my json file I have an array called minecraft and I am trying to insert new data into that array but php won't do it . instead it puts it outside of the array I tried to insert the array name in the variable $json but it will break the json file completely .
How do I fix it?