title: Having difficulty modifying JSON object in PHP Script
body: <p>Hi we have been trying to create a game for a school project and cannot figure out how to modify the JSON code through PHP.</p>
  
  <p>Here is the PHP code we made to modify an object's value from the key,</p>
  
  <pre><code>    $json_object = file_get_contents('players.json');
      $data = json_decode($json_object);
  
      foreach($data as $key)
      {
          $data['winning_cards'] = [1,2,3];
      }
      $json_object = json_encode($data);
      file_put_contents('players.json', $json_object);
  </code></pre>
  
  <p>After completing we now have 0 in front in the JSON file,</p>
  
  <pre><code>{"0":{"username":"test_username","character":"TEST","position":"6","current_turn":false,"cards":[],"winning_cards":[]},"winning_cards":[1,2,3]}
  </code></pre>
  
  <p>We want the code as is without the "0" and the existing winning_cards with the new array value from the PHP script. It is getting placed afterwards and changing the JSON file completely.</p>