Get the number of quiz attempts by a user_id for a specific quiz_id

/* Get the number of attempt by a user_id for a specific quiz_id */
function get_user_quiz_attempts($user_id, $quiz_id = 0) {
	$attempts_count = 0;
	
	$usermeta = get_user_meta( $user_id, '_sfwd-quizzes', true );
	if (!empty( usermeta ) ) {
		$usermeta = maybe_unserialize( $usermeta );

		if ( ! is_array( $usermeta ) ) { 
			$usermeta = array();
		}

		foreach ( $usermeta as $k => $v ) {
			if ( $v['quiz'] == $quiz_id ) { 
				$attempts_count++;
			} 
		}
	}
	
	return $attempts_count;
}