I have this PHP code:
$goodname = 'name'; $goodlvl = '6'; $name = "goods.json"; $arr = array( 'name' => $goodname, 'lvl' => $goodlvl ); file_put_contents($name, json_encode($arr, JSON_UNESCAPED_UNICODE)); It creates a PHP array, converts it to JSON format, and shoves goods.json
It seems everything works, but not as I need. This is what this script does with the goods.json file:
{"name":"123","lvl":"6"} It carries the elements of the array. I want to know how to make the PHP script give this array a name to make something like this
{ "account" : { "name: "123", "lvl" : "6" } } All in order to be able to create these accounts and specify (drive in the inputs) statistics: name and level, and the PHP script created them and entered them in goods.json