title: how to do a foreach loop in php?
body: <p>I have a function that has a query and a foreach loop:</p>
  
  <pre><code>$sql = "SELECT * FROM explore WHERE id = $id";
  $object = $this-&gt;db-&gt;select($sql);
  
  foreach($object as $val){
      $results = array('id'=&gt;$val-&gt;id, 'from_id'=&gt;$val-&gt;from_id);
      $this-&gt;result[] = $this-&gt;notify($results);  
      }
  
  return $results;
  </code></pre>
  
  <p>The issue here is that if I <code>return $object</code> I get 2 records:</p>
  
  <pre><code>Array
  (
  [0] =&gt; stdClass Object
      (
          [from_id] =&gt; 6
          [id] =&gt; 3
      )
  
  [1] =&gt; stdClass Object
      (
          [from_id] =&gt; 6
          [id] =&gt; 1
      )
  
  )
  </code></pre>
  
  <p>and <code>return $results</code> has 1 record:</p>
  
  <pre><code>Array
  (
      [id] =&gt; 1
      [from_id] =&gt; 6
  )
  </code></pre>
  
  <p>Also if I <code>return $this-&gt;result;</code>, <code>$this-&gt;result[] = $this-&gt;notify($results);</code> does run twice but uses the same record twice returned by <code>$results</code> instead of using the 2 records from <code>$object</code></p>
  
  <p>Hope you guys can understand my issue.</p>
  
  <p>ps: I am using the zend framework</p>
  
  <p>Any ideas?</p>
  
  <p><strong>Edit</strong>: <code>notify</code> is a function in another class</p>