title: php remove object from array of objects
body: <p>I'm trying to remove an object from an array of objects by its' index. Here's what I've got so far, but i'm stumped.</p>
  <pre><code>$index = 2;
  
  $objectarray = array(
  0=&gt;array('label'=&gt;'foo', 'value'=&gt;'n23'),
  1=&gt;array('label'=&gt;'bar', 'value'=&gt;'2n13'),
  2=&gt;array('label'=&gt;'foobar', 'value'=&gt;'n2314'),
  3=&gt;array('label'=&gt;'barfoo', 'value'=&gt;'03n23')
  );
  
  //I've tried the following but it removes the entire array.
  foreach ($objectarray as $key =&gt; $object) {
   if ($key == $index) {
     array_splice($object, $key, 1);
     //unset($object[$key]); also removes entire array.
   }
  }
  </code></pre>
  <p>Any help would be appreciated.</p>
  <h1>Updated Solution</h1>
  <pre><code> array_splice($objectarray, $index, 1); //array_splice accepts 3 parameters 
      //(array, start, length) removes the given array and then normalizes the index
      //OR 
      unset($objectarray[$index]); //removes the array at given index
      $reindex = array_values($objectarray); //normalize index
      $objectarray = $reindex; //update variable 
  </code></pre>