So I ended up using a combination of the array_filter function and the in_array function to retrieve all custom roles like this:
<?php
function check_roles($userRole) {
$default_roles = array('Administrator', 'Editor', 'Author', 'Contributor', 'Subscriber');
if (!in_array($userRole, $default_roles)) {
return $userRole;
}
}
$all_roles = wp_roles()->get_names();
$custom_roles = array_filter($all_roles, 'check_roles');
foreach ($custom_roles as $role) {
echo $role;
}
?>