title: How can I call a function within the foreach loop and avoid redeclaring error
body: <blockquote>
    <p><strong>Fatal error</strong>: Cannot redeclare short_count() (previously declared in
    <code>below-code</code>:22)
    in
    <code>below-code</code>
    on line 20</p>
  </blockquote>
  
  <pre><code>&lt;?php
  require_once( './wp-blog-header.php' ); 
  query_posts('&amp;showposts=-1');
  
      if(have_posts()) {
  
          while(have_posts()) : the_post();
  
              $prmlks = '"'. get_the_permalink(). '",';
              $links = array( $prmlks );
              foreach ($links as $items) {
                  $json_data = get_transient( 'cache_'. $id .'_tr' );
                  if ($json_data === false) {
                      $id = get_the_ID();
                      $json = file_get_contents( 'http://api.facebook.com/restserver.php?method=links.getStats&amp;format=json&amp;urls=' . $items . '&amp;pretty=1' );
                      $json_data = json_decode($json, true);
                      set_transient( 'cache_'. $id .'_tr', $json_data, 3600 );
                  }
  
                  function short_count() {
  
                      $num = $json_data[0]['total_count'];
                      if(empty ($num) ) {
                          return 'n/a';
                      } else {
                      if( $num &lt; 1000 ) return $num;
                      $x = round($num);
                      $x_number_format = number_format($x);
                      $x_array = explode(',', $x_number_format);
                      $x_parts = array('k', 'm', 'b', 't');
                      $x_count_parts = count($x_array) - 1;
                      $x_display = $x;
                      $x_display = $x_array[0] . ((int) $x_array[1][0] !== 0 ? '.' . $x_array[1][0] : '');
                      $x_display .= $x_parts[$x_count_parts - 1];
                      return  $x_display;
                      }
  
                  }
  
  
                  $short_count = short_count();
                  echo $short_count;
  
  }
          endwhile;
  
      }
  
  ?&gt;
  </code></pre>
  
  <p>The question is: <strong>how can I call a function within the <code>foreach</code> loop ?</strong></p>
  
  <p>I want to keep the function within the <code>foreach</code> loop so as to get the dynamic variables..</p>