title: Removing an element from an array which is an element of an object
body: <p>I'm working on a filter system to filter out food items being displayed on a menu. Every document in the menu collection contains the name of the category (or course if you will) and an array of food items.</p>
  
  <p>I've tried various solutions such as the following code which gets me closer to the desired output.</p>
  
  <pre><code>foreach($menu as $category){
  
     foreach($category["fooditems"] as $fooditem){
  
         if ($fooditem["vegetarian"] == false){
                   if (($key = array_search($fooditem, (array) $category["fooditems"])) !== false) 
                      unset($category["fooditems"][$key]);        
      }
    }
  }
  
  </code></pre>
  
  <p>Before:</p>
  
  <pre><code>
  {
      "category" : "Starters",
      "fooditems" : [ 
          {
              "name" : "No meat",
              "vegetarian" : true,
  
          }, 
          {
              "name" : "Horse Meat",
              "vegetarian" : false,
          }, 
          {
              "name" : "Some more meat",
              "vegetarian" : false,
          }
      ]
  }
  
  </code></pre>
  
  <p>Expected after:</p>
  
  <pre><code>
  {
      "category" : "Starters",
      "fooditems" : [ 
          {
              "name" : "No meat",
              "vegetarian" : true,
  
          }
      ]
  }
  
  </code></pre>
  
  <p>Actual after:</p>
  
  <pre><code>
  {
      "category" : "Starters",
      "fooditems" : [ 
          {
              "name" : "No meat",
              "vegetarian" : true,
  
          }, 
          {
              "name" : "Some more meat",
              "vegetarian" : false,
          }
      ]
  }
  
  </code></pre>
  
  <p>The problem is after it spots a non-vegetarian food item and unsets it, it stops looping. I have no idea why this occurs.</p>
  
  <p>Thank you to anyone who answers :)</p>