title: Silverstripe 3 - foreach loop to return multiple objects
body: <p>I've got an ItemObject with the field 'Categories'. In this field, the IDs of the related CategoryPages are stored as string. e.g 25,30,8.</p>
  
  <p>Now I want to return only the ItemObjects, where the CategoryPage ID is in the string of the Categories Field.</p>
  
  <p>To achieve this, I created this function</p>
  
  <pre><code>public function getItemsForCategory() {
      $items = Item::get();
      foreach($items as $item) {
          $categories = $item-&gt;Categories;
          $explode = explode(',', $categories);
          if( in_array($this-&gt;ID, $explode) ) {
              echo $item-&gt;ID . '&lt;br&gt;';
          }
      }   
  }
  </code></pre>
  
  <p>It puts the correct IDs of the ItemObject for this one Category in the Page. So it works, but I want to return the ItemObjects for the Category so I replaced the <code>echo $item-&gt;ID ...;</code> with <code>return $item;</code> but it seems that this is only returning the first Item for the Category.</p>
  
  <p>Can someone please tell me my mistake?</p>
  
  <p>Thank you in advance!</p>