Prueba en asignar antes de imprimir.
Código:
do {
$subtotal[] = $row['total'];
$totales[] = $row['total'];
if( new_group() {
print_headers_grupo()
}
print_data($row)
if( new_group() ) {
print_subtotal( array_sum( $subtotal ) );
$subtotal = array();
}
} while ( $row = fetch_row() );
print_totales($totales);
Saludos.