Register multiple users in one form

Update

Found this awesome post http://tommcfarlin.com/create-a-user-in-wordpress/ that helped me solve the issue.

It was for a product in Shopp where a user can sign up multiple users for a training course, and each email needed to be registered as a subscriber.

This is the final code..

<?php
add_action( 'shopp_order_success', 'create_subscribers' );

function create_subscribers( $Purchase ) {

    foreach ( $Purchase->purchased as $purchase ) :

        $i = 1;
        while ( isset( $purchase->data['Email '.$i] ) ) :

            $email_address = $purchase->data['Email '.$i];

            if ( null == username_exists( $email_address ) ) :

                // Generate the password and create the user
                $password = wp_generate_password( 12, false );
                $user_id  = wp_create_user( $email_address, $password, $email_address );

                // Set the nickname
                wp_update_user(
                    array(
                        'ID'       =>    $user_id,
                        'nickname' =>    $email_address
                    )
                );

                // Set the role
                $user = new WP_User( $user_id );
                $user->set_role( 'subscriber' );

                // Email the user
                wp_mail( $email_address, 'Welcome!', 'Your Password: ' . $password );

            endif;
            $i++;
        endwhile;
    endforeach;
}