title: Foreach loop executes only first value with return, but returns all values with echo
body: <p>I'm trying to create an affiliate leaderboard using affiliatewp. I'm able to get every value that I want, however, in the function I'm using a foreach loop that calls every affiliate and displays the "sales" for the month.</p>
  
  <pre><code>function affiliate_leaderboard_function() {
  global $wpdb;
  
  $getallreferrals = $wpdb-&gt;get_results( "SELECT * FROM `wp_affiliate_wp_referrals`");
  $getallaffiliates = $wpdb-&gt;get_results( "SELECT * FROM `wp_affiliate_wp_affiliates`");
  $current_month = get_the_date("m");
  $current_year = get_the_date("Y");
  $current_date = get_the_date("Y-m-d");
  $lastday = date('t',strtotime($current_date));
  
  foreach ($getallaffiliates as $theaffiliate) {
      $user_id = get_userdata( $theaffiliate-&gt;user_id );
      $userfirstname = $user_id-&gt;first_name;
      $userlastname = $user_id-&gt;last_name;
      $totalreferrals = $theaffiliate-&gt;referrals;
      $affiliate_id = $theaffiliate-&gt;affiliate_id;
      $getaffreferrals = $wpdb-&gt;get_results( "SELECT `date` FROM `wp_affiliate_wp_referrals` WHERE `affiliate_id` = $affiliate_id AND `date` &gt;= '$current_year-$current_month-01:00:00:00' AND `date` &lt; '$current_year-$current_month-$lastday:23:59:59' ORDER BY `wp_affiliate_wp_referrals`.`referral_id` ASC");//Get all referrals by affiliate id
      $closerstring = $userfirstname." | This Month's Sales: ".count($getaffreferrals)."&lt;br&gt;";
      if(!empty($getaffreferrals)){
          echo $closerstring;
      }
  }
  }
  add_shortcode('affiliate_leaderboard' , 'affiliate_leaderboard_function');
  </code></pre>
  
  <p>So when I put the shortcode in place, and with using "echo $closerstring" it spits out all of the correct data, user's first name followed by how many sales they've had in the current month. BUT the shortcode outputs at the top of the content.</p>
  
  <p>When I switch it to "return $closerstring" it only returns one affiliate instead of all affiliates in the foreach loop. I have no clue how to get it to show all values like the echo function does, but I need it to appear in the proper location...</p>