title: PHP foreach value in array
body: <p>I am making an <code>Staff Online</code> section for members to see weather any staff member is in-game to help them or not. I began tackling this idea with an array of the <code>Staff Members</code> account ID's. It looks something like this:</p>
  
  <pre><code>$this-&gt;view-&gt;staffAdmins = array(64, 80, 96);
  </code></pre>
  
  <p>Then I used a <code>foreach</code> statement to get the following details for each account:</p>
  
  <ul>
  <li>Are they logged in?</li>
  <li>If so, use their <code>ID</code> from the array and get more information from the <code>users</code> table</li>
  </ul>
  
  <p>My <code>foreach</code> statement looks like this:</p>
  
  <pre><code>foreach ($this-&gt;view-&gt;staffAdmins as $query) {
      //Are they logged in?
      $sql = "SELECT * FROM point WHERE uid = :ID AND zoneid &gt; -1";
      $arr = array(":ID" =&gt; $query);
      $this-&gt;view-&gt;result = $this-&gt;database-&gt;DBCtr($sql, $arr);
      //Get their details!
      $sql = "SELECT * FROM users WHERE ID = :ID";
      $arr = array(":ID" =&gt; $query);
      $this-&gt;view-&gt;staffmem = $this-&gt;database-&gt;DBQry($sql, $arr);
      $this-&gt;view-&gt;name = $this-&gt;view-&gt;staffmem[0]['name'];
      $this-&gt;view-&gt;truename = $this-&gt;view-&gt;staffmem[0]['truename'];
      if ($this-&gt;view-&gt;result == 1){
          echo $this-&gt;view-&gt;truename;
      }
  }
  </code></pre>
  
  <p>That returns the following output:</p>
  
  <pre><code>Hulu is Online
  Cookiez is Online
  </code></pre>
  
  <p>Which is exactly what I need, but it outputs that at the very top of the page, which is not what I need. And when I try to put <code>echo $this-&gt;truename;</code> in the correct spot on the actual page it renders to, the output is</p>
  
  <pre><code>Cookiez is Online
  </code></pre>
  
  <p>It only gets the second staff member's <code>ID (80)</code> in the array, while we are both logged in at the same time.</p>
  
  <p>Also, this is the code I am using to <code>attempt</code> to get same output as the one the working <code>foreach</code> statement. This is on the page the class renders too.</p>
  
  <pre><code>foreach ($this-&gt;staffAdmins as $staff){
      if ($this-&gt;result == 1){
          foreach ($this-&gt;staffmem as $logged){
          echo $logged['truename'];
          }
      }
  }
  </code></pre>