Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to add item to the json file formatted array
    primarykey
    data
    text
    <p>I am using using just 1 data to insert in my json file.</p> <pre><code>$data=$_POST['myusernamer']; $inp = file_get_contents('7players.json'); $tempArray = json_decode($inp); array_push($tempArray, $data); $jsonData = json_encode($tempArray); file_put_contents('7players.json', $jsonData); </code></pre> <p>So this is how my json file looks. I just want to add 1 player at the end.</p> <pre><code>{ "players":[ { "name":"Moldova", "image":"/Images/Moldova.jpg", "roll_over_image":"tank.jpg" }, { "name":"Georgia", "image":"/Images/georgia.gif", "roll_over_image":"tank.jpg" }, { "name":"Belarus", "image":"/Images/Belarus.gif", "roll_over_image":"tank.jpg" }, { "name":"Armenia", "image":"/Images/armenia.png", "roll_over_image":"tank.jpg" }, { "name":"Kazahstan", "image":"/Images/kazahstan.gif", "roll_over_image":"tank.jpg" }, { "name":"Russia", "image":"/Images/russia.gif", "roll_over_image":"tank.jpg" }, ], "games" : [ { "matches" : [ { "player1id":"*", "player2id":"*", "winner":"*" }, { "player1id":"*", "player2id":"*", "winner":"*" }, { "player1id":"*", "player2id":"*", "winner":"*" }, { "player1id":"*", "player2id":7, "winner":"*" }, { "player1id":"*", "player2id":"*", "winner":"*" }, { "player1id":"*", "player2id":"*", "winner":"*" }, { "player1id":"*", "player2id":"*", "winner":"*" } ] }, { "matches" : [ { "player1id":"*", "player2id":"*", "winner":"*" }, { "player1id":"*", "player2id":"*", "winner":"*" }, { "player1id":"*", "player2id":"*", "winner":"*" }, { "player1id":"*", "player2id":7, "winner":"*" }, { "player1id":"*", "player2id":"*", "winner":"*" }, { "player1id":"*", "player2id":"*", "winner":"*" }, { "player1id":"*", "player2id":"*", "winner":"*" }, ] } ] } </code></pre> <p>My question is, how do I add player at the end? And I would also like to know how to update </p> <pre><code>player1id":"*", "player2id":"*", "winner":" </code></pre> <p>in the match array.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload