test2

<?php
$wp_roles = wp_roles();
$result   = count_users();

foreach ( $result['avail_roles'] as $role => $count )
{
    if ( 0 == $count )
        continue; //pass role none

    $args = array(
        'role' => $role
    );

    $users = get_users( $args );
    $user  = array();
    for ( $i = 0; $i < $count ; $i++ )
        $user[] = esc_html( $users[ $i ]->display_name ); //show display name

    //output
    echo wp_sprintf( '<h2>%1$s</h2><ul><li>%2$s</li></ul>',
        esc_html( $wp_roles->role_names[ $role ] ),
        implode( '</li><li>', $user )
    );
}
?>