title: Display total number of items from while loop outside of it php
body: <p>I have a PHP while loop and i'm trying to use a counter to display the total number of items (<code>.question</code>) that are within it. I'm trying to echo the contents of $child_i outside of the while loop to do this but the code below doesn't work. Whats the best way of achieving this?</p>
  
  <p><strong>EDIT</strong>
  Updated to show full code</p>
  
  <pre><code>&lt;?php if( have_rows('faqs') ): ?&gt;
     &lt;ul class="responsive-accordion responsive-accordion-default bm-larger"&gt;
        &lt;?php while( have_rows('faqs') ): the_row(); ?&gt;
          &lt;li&gt;
             &lt;div class="responsive-accordion-head"&gt;&lt;span class="ico arrow-right"&gt;&lt;/span&gt;&lt;?php the_sub_field('category_name'); ?&gt; &lt;span class="faq-counter"&gt;
             &lt;!-- TRYING TO ECHO $CHILD_I ON THE LINE BELOW BUT NOT WORKING --&gt;
             &lt;?php echo($child_i); ?&gt; Questions&lt;/span&gt;&lt;/div&gt;
             &lt;!-- $CHILD_I IS DEFINED ON THE NEXT LINE --&gt;
             &lt;?php if( have_rows('questions') ): $child_i = 0; ?&gt;
                &lt;!-- THIS ECHO WORKS --&gt;
                &lt;div class="responsive-accordion-panel &lt;?php echo($child_i); ?&gt;"&gt;
                  &lt;?php while( have_rows('questions') ): the_row(); ?&gt;
                    &lt;div class="question"&gt;
                       &lt;h6&gt;&lt;?php the_sub_field('question'); ?&gt;&lt;/h6&gt;   
                       &lt;p&gt;&lt;?php the_sub_field('answer'); ?&gt;&lt;/p&gt;
                    &lt;/div&gt;
                  &lt;?php $child_i++; endwhile; ?&gt;
              &lt;/div&gt;
             &lt;?php endif; //if( get_sub_field('questions') ): ?&gt;
             &lt;/div&gt;
          &lt;/li&gt;   
     &lt;?php endwhile; // while( has_sub_field('to-do_lists') ): ?&gt;
    &lt;/ul&gt;
  &lt;?php endif; // if( get_field('to-do_lists') ): ?&gt;
  </code></pre>