title: How to count in array by using another array in PHP?
body: <p>I have a groups array and members array. Group_one can be Member, Admin etc</p>
  
  <pre><code>//groups:
  Array
  (
  [0] =&gt; Array
      (
          [id] =&gt; 1
          ...
          [name] =&gt; Group_one
          ...
      )
  [1] =&gt; Array
      (
          [id] =&gt; 2
          ...
          [name] =&gt; Group_two
          ... 
      )
  ...
  </code></pre>
  
  <hr>
  
  <pre><code>//members:
  CI_DB_mysql_result Object
  (
  [conn_id] =&gt; Resource id #12
  [result_id] =&gt; Resource id #55
  [result_array] =&gt; Array
      (
          [0] =&gt; Array
              (
                  [id] =&gt; 2
                  ...
                  [group] =&gt; Group_2
                  [group_id] =&gt; 2
  
              )
          [1] =&gt; Array
              (
                  [id] =&gt; 5
                  ...
                  [group] =&gt; Group_four
                  [group_id] =&gt; 4
  
              )
              ...
  </code></pre>
  
  <p>Now I want to count how many in Group_one, Group_two etc.</p>
  
  <p>I tried the following but not working.</p>
  
  <pre><code>foreach($groups as $group)
  {
    foreach ($members-&gt;result_array() as $key =&gt; $list)
    {
      if($group['id']==$list['group_id'])
      {   
          $stack[] = array();
          array_push($stack,$list);
      }
    }
  }
  echo "&lt;pre&gt;stack is:";
  //print_r($stack);
  echo count($stack);
  echo"&lt;/pre&gt;end of stack";
  </code></pre>