title: deleting JSON array element in PHP, and re-encoding as JSON
body: <pre><code>function deleteNews($selected) {
      $file = file_get_contents('news.json', true);
  
      $data=json_decode($file,true);
      unset($file);
  
  foreach($selected as $index){
   unset($data[$index]);
   }
  
  
    $result=json_encode($data);
  
    file_put_contents('news.json', $result);
      echo $result;
      unset($result);
      $url="./deleteNews.php";
     //redirect($url);
      }
  </code></pre>
  
  <p>The above function is supposed to delete an entry from a JSON like :</p>
  
  <pre><code>[
       {
             "dummy":"dummy",
             "dummy1":"dumy"
        },
        {
             "dummy":"dummy1",
             "dummy1":"dummy"
        }
  ]
  </code></pre>
  
  <p>But in the end the function inserts numerical indexes in the JSON, which is not desirable. </p>
  
  <p>The result is like </p>
  
  <pre><code>[
      "0":
         {
            "dummy":"dummy",
            "dummy1":"dumy"
         },
       "1":
         {
             "dummy":"dummy1",
             "dummy1":"dummy"
         }
   ]
  </code></pre>
  
  <p>How can I get my original JSON format from this? I don't want that 0 1 2 index part.</p>
  
  <p>N.B: it's the <code>foreach</code> that does this. Without the <code>foreach</code>, the JSON is created as expected.</p>