foreach ($stats as $stat) {
     if ($stat !== 'subs') {
         $output .= '<div class="' . $stat . '">';
         if ($stat == 'rating') {
             if ($player_detail['rating'] > 0) {
                 //$player_details[$player->ID]['appearances'] = $player_stats[$team][$season]['total']['appearances'];
                 // if ( $season ) {
                 // 	$player_details[$player->ID]['appearances'] = '';
                 // 	$player_details[$player->ID]['appearances'] = $player_stats[0][ $season ]['total']['appearances'];
                 // } else {
                 // 	$player_details[$player->ID]['appearances'] = '';
                 // 	$player_details[$player->ID]['appearances'] = $player_stats[0][0]['total']['appearances'];
                 // }
                 $r = $player_detail['rating'];
                 $a = $player_detail['appearances'];
                 $avrating = wpcm_divide($r, $a);
                 $output .= sprintf("%01.2f", round($avrating, 2));
             } else {
                 $output .= '0';
             }
         } elseif ($stat == 'appearances') {
             if (array_key_exists('subs', $player_detail)) {
                 $output .= $player_detail['appearances'] . ' (' . $player_detail['subs'] . ')';
             } else {
                 $output .= $player_detail['appearances'];
             }
         } else {
             $output .= $player_detail[$stat];
         }
         $output .= '</div>';
     }
/**
 * Player profile stats table.
 *
 * @access public
 * @param array
 * @param string $team
 * @param string $season
 * @return void
 */
function wpcm_profile_stats_table($stats = array(), $team = 0, $season = 0)
{
    $id = get_the_ID();
    if (array_key_exists($team, $stats)) {
        if (array_key_exists($season, $stats[$team])) {
            $stats = $stats[$team][$season];
        }
    }
    $wpcm_player_stats_labels = wpcm_get_sports_stats_labels();
    $stats_labels = array('appearances' => '<a title="' . __('Games Played', 'wp-club-manager') . '">' . __('GP', 'wp-club-manager') . '</a>');
    $stats_labels = array_merge($stats_labels, $wpcm_player_stats_labels);
    ?>

	<table>
		<thead>
			<tr>
				<?php 
    foreach ($stats_labels as $key => $val) {
        if (get_option('wpcm_show_stats_' . $key) == 'yes') {
            ?>

						<th><?php 
            echo $val;
            ?>
</th>
					<?php 
        }
    }
    ?>
			</tr>
		</thead>
		<tbody>
			<tr>
				<?php 
    foreach ($stats_labels as $key => $val) {
        if ($key == 'appearances') {
            if (get_option('wpcm_show_stats_appearances') == 'yes') {
                if (get_option('wpcm_show_stats_subs') == 'yes') {
                    $subs = get_player_subs_total($id, $season, $team);
                    if ($subs > 0) {
                        $sub = ' <span class="sub-appearances">(' . $subs . ')</span>';
                    } else {
                        $sub = '';
                    }
                }
                ?>
					
							<td><span data-index="appearances"><?php 
                wpcm_stats_value($stats, 'total', 'appearances');
                echo get_option('wpcm_show_stats_subs') == 'yes' ? $sub : '';
                ?>
</span></td>

						<?php 
            }
        } elseif ($key == 'rating') {
            $rating = get_wpcm_stats_value($stats, 'total', 'rating');
            $apps = get_wpcm_stats_value($stats, 'total', 'appearances');
            $avrating = wpcm_divide($rating, $apps);
            if (get_option('wpcm_show_stats_rating') == 'yes') {
                ?>
					
							<td><span data-index="rating"><?php 
                echo sprintf("%01.2f", round($avrating, 2));
                ?>
</span></td>

						<?php 
            }
        } else {
            if (get_option('wpcm_show_stats_' . $key) == 'yes') {
                ?>

							<td><span data-index="<?php 
                echo $key;
                ?>
"><?php 
                wpcm_stats_value($stats, 'total', $key);
                ?>
</span></td>
						<?php 
            }
        }
    }
    ?>
				
			</tr>
		</tbody>
	</table>
<?php 
}