title: PHP Multidimensional Array loop and group by value
body: <p>I have a multidimensional array that looks like this:</p>
  
  <pre><code>Array ( 
   [0] =&gt; Array ( [A] =&gt; Apple ) 
   [1] =&gt; Array ( [A] =&gt; Banana ) 
   [2] =&gt; Array ( [A] =&gt; Strawberry ) 
   [3] =&gt; Array ( [B] =&gt; Computer ) 
  ) 
  </code></pre>
  
  <p>Now i would like to loop through that array and output the values grouped by [A],[B], …
  But in my case I don’t know if there is an [A], [B] or [C].</p>
  
  <p>The Result should look like this:</p>
  
  <pre><code>[A] Apple, Banana, Strawberry
  [B] Computer
  </code></pre>
  
  <p>This is my code so far:</p>
  
  <pre><code>$service_links[] = array();
  $sl_i = 0;
  
  if( have_rows('services') ):
  
  // loop through the rows of data
  while ( have_rows('services') ) : the_row();
  
      if( get_row_layout() == 'service_category' ) {
  
          $service_category_taxonomy = get_sub_field('service_category_taxonomy');
          $service_links[$sl_i][$service_category_taxonomy] = get_sub_field('service_group_title');
  
          $sl_i++;
      }
  
  endwhile;
  
  endif;
  
  foreach ( $service_links as $var ) {
     echo " ????? ";
  }
  </code></pre>
  
  <p>Thank you very much!</p>