php - Adding elements to an array inside of JSON -


i have json looks this:

{     people: [] } 

my goal @ moment add elements array of people. in end able remove elements again.

i have tried like:

<?      $file = "test.json";     $json = file_get_contents($file);     $get = json_decode($json);      array_push($get->people, $_get['person']);      file_put_contents($file, json_encode($get));  ?> 

however, not work. i'm pretty sure there easier solution this. help.

you have invalid json. keys must quoted.

{"people": []} 

otherwise, code should work. although recommend not using php short open tags , filtering user input.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -