title: How to save fetched rows from while loop into a new array?
body: <p>Let's say I have this loop in my header.php:</p>
  
  <pre><code>&lt;div id="top-20"&gt;
      &lt;h2 class="top-20-title"&gt;TOP 20 TEAMS&lt;/h2&gt;
  
      &lt;div class="top-20-content"&gt;
  
          &lt;?php
              $params = array(
                 'limit'   =&gt; -1 // get everything
              );
  
              $matches = pods( 'matches', $params );
  
              if ( 0 &lt; $matches-&gt;total() ) {
                  while ( $matches-&gt;fetch() ) {
              ?&gt;
  
                   &lt;?php echo $matches-&gt;field( 'winner_team' ); ?&gt;
                   &lt;br&gt;
  
              &lt;?php
                      } // end of while loop
                  } // end of if any exists
              ?&gt;
  
      &lt;/div&gt;&lt;!-- /top-20-content --&gt;  
  &lt;/div&gt;&lt;!-- /top-20 --&gt;  
  </code></pre>
  
  <p>And this is what my simplified table looks like:</p>
  
  <pre><code>id | team_1 | team_2 | winner_team
  --------------------------------
  1  | 3      | 15     | 3
  --------------------------------
  2  | 20     | 8      | 8
  --------------------------------
  3  | 18     | 11     | 18
  --------------------------------
  4  | 8      | 7      | 8
  --------------------------------
  ...
  </code></pre>
  
  <p>But I want instead of echoing inside while loop like</p>
  
  <pre><code>&lt;?php echo $matches-&gt;field( 'winner_team' ); ?&gt;
  </code></pre>
  
  <p>create a new array i.e. <strong>$matches_array</strong> which will contain 2 columns like <strong>id_new</strong> and <strong>winner_team_new</strong> and save the value of <strong>winner_team</strong> in <strong>winner_team_new</strong> instead of echoing it directly inside while loop.</p>
  
  <p><strong>Then I would like to loop this new created array $matches_array inside another while loop after groupby occurrences of winner_team_new and orderby them DESC.</strong> </p>
  
  <p>So, I will get something like this:</p>
  
  <pre><code>8
  3
  18
  </code></pre>
  
  <p>instead of what I am currently getting when using echo in while loop:</p>
  
  <pre><code>3
  8
  18
  8
  </code></pre>
  
  <p>Why I can not just do it inside sql? I need to be done using another array not using conditions in $params or sql array due to this bug: <a href="https://github.com/pods-framework/pods/issues/595" rel="nofollow">https://github.com/pods-framework/pods/issues/595</a> and the fact that pods framework is too complicated for my to make my own code adjustements into core so I would like to bypass this by working with an array that will be created from while loop.</p>
  
  <p><strong>So, what I need is to create an array and rearange the results based on occurrences of winner_team from the most to the less.</strong> </p>
  
  <p>I have tried using </p>
  
  <pre><code>$matches_array = array_count_values(array_map($matches,array_keys($new_row)));
  </code></pre>
  
  <p>And then loop it in while loop but it is not working at all.</p>
  
  <p>I need help with the count array/group by part. </p>
  
  <p>I don't know practically anything about it.</p>
  
  <p>I just guess that I need after grouping based on the same <strong>winner_team</strong> field create a new field e.g. <strong>wins</strong> where the number of occurrences for every team(based on winner_team) value will be stored. And then order that new array DESC.</p>
  
  <p><strong>Btw. all columns in the table are INTEGERS</strong></p>
  
  <p><strong>EDIT 2:</strong>
  I have figured out how to store values from the while loop inside a new array called $matches_array and the code looks like this:</p>
  
  <pre><code>&lt;div id="top-20"&gt;
      &lt;h2 class="top-20-title"&gt;TOP 20 TEAMS&lt;/h2&gt;
  
      &lt;div class="top-20-content"&gt;
  
          &lt;?php
              $params = array(
                 'limit'   =&gt; -1 // get everything
              );
  
              $matches = pods( 'matches', $params );
  
              if ( 0 &lt; $matches-&gt;total() ) {
                  while ( $matches-&gt;fetch() ) {
              ?&gt;
  
                   &lt;?php // echo $matches-&gt;field( 'winner_team' ); ?&gt;
                        &lt;?php $row_array = $matches-&gt;field( 'winner_team' ); ?&gt;
                        &lt;?php $matches_array[]; ?&gt;
  
                   &lt;br&gt;
  
              &lt;?php
                      } // end of while loop
                  } // end of if any exists
              ?&gt;
  
      &lt;/div&gt;&lt;!-- /top-20-content --&gt;  
  &lt;/div&gt;&lt;!-- /top-20 --&gt;
  </code></pre>
  
  <p>Now, I need probably do a foreach loop after a groupby(based on occureces of the numbers in winner_team field) and order the result before the output DESC.</p>
  
  <p>Any advice how to do that?  </p>