I'm very new to both JSON and PHP but I'm building a game that needs a seperate database that keeps track of the doors that are locked and unlocked in a maze.
My JSON file looks like this:
{ "doors":
[
{"left":true, "right":false, "bottom":false},
{"left":false, "right":false, "bottom":false},
{"right":false, "bottom":false, "top":false}
]
}
and my PHP file looks like this:
$jsonString = file_get_contents('info.json');
$data = json_decode($jsonString);
$data["doors"][0]["right"] = true;
$newJsonString = json_encode($data);
file_put_contents('info.json', $newJsonString);
I'm calling this using ajax in javascript and I can read the file if I use var_dump($data)
but as soon as I try to edit the file I get a 500 error. I feel like I'm really close, but I'm just really stuck right now. If someone could help me out that would be really great. Thanks.