title: How to unset a json object
body: <p>What I am writing is a temporarely banning script for people who like to pester my site with small botnets.</p>
  
  <p>The only problem I am having is how to unset a json object.</p>
  
  <p>I have the following code</p>
  
  <pre><code>/* JSON blocking script written by Michael Dibbets
   * Copyright 2012 by Michael Dibbets
   * http://www.facebook.com/michael.dibbets - mdibbets[at]outlook.com
   * Licenced under the MIT license http://opensource.org/licenses/MIT
   */
      // Turn on error reporting
      ini_set("display_errors", 1);
      error_reporting(E_ALL);  
      // Create our codeigniter filepath
      $filepath = FCPATH.'pagemodules/blocked.json';
      // Load file helper to be able to be lazy
      $this-&gt;load-&gt;helper('file');
      // Read the json file
      $data = read_file($filepath,'c+');
      // Have we succeeded? Then continue, otherwise fail graciously
      if($data !== false)
          {
              // Let's make it readable
          $json = json_decode($data);
              // Display it for debug purposes
          echo $data;
              // Iterate through every object, get the key to be able to unset it
          foreach($json as $key =&gt; $obj)
              {
                      // Dump the object for debug purposes
              var_dump($obj);
              echo "&lt;P&gt;";
                      // Has it's life time expired?
              if((int)$obj-&gt;{'endtime'} &lt; strtotime("+2 hours 2 minutes"));
                  {
                              // remove the object from the array
                  unset($json[$key]);
                  }
              }
              // Remove the file so we can overwrite it properly
          unlink($filepath); 
          }
      // Add some values to our array
      $json[] = array('ip' =&gt; $_SERVER['REMOTE_ADDR'],'endtime' =&gt; strtotime('+2 hours'));
      // Encode it
      $data = json_encode($json);
      // Write it to file
      write_file($filepath,$data,'c+'); 
  </code></pre>
  
  <p>The problem I am having is that json encode doesn't encode it as array but as an object. The problem is that the following doesn't work:</p>
  
  <pre><code>// This gives the error Fatal error: Cannot use object of type stdClass as array in /public_html/ocs_application/controllers/quick.php on line 37
  unset($json[$key]);
  // This doesn't report anything, and does nothing
  unset($json-&gt;{$key});
  </code></pre>
  
  <p>How do I unset the json object?</p>