PHP数组 - 按电子邮件地址域排序(备用)

I have an array of email addresses I am sending emails to.

I would like to sort them by alternating domain names, so if I have 30 @gmail.com, 30 @yahoo.com and 30 @aol.com, the sort would result in a @gmail.com, then @yahoo.com, then @aol.com, then @gmail.com again, etc.

The sort would alternate as much as possible so that there would be as few identical domain names in a row.

Why: To prevent being considered as a source of spam, its best to "throttle" email sending, or sleep between each send so mail servers are not hit quickly many times in a short time spam. Instead, I would like to do that above to create a lag between times an email provider is hit by me, but without stopping my script and causing a delay to my end user.

I may do it like this:

$organized_emails = array();
$needle_key = 0;
$needle_search = array('gmail', 'yahoo', 'aol', 'others');

while(true) {
    $current_value = array_shift($emails);
    if(strpos($current_value, $needle_search[$needle_key]) !== false) {
        $organized_emails[] = $current_value;
        $needle_key++;
        if($needle_key > 3) {
            $needle_key = 0;
        }
    } else {
        array_push($emails, $current_value);
    }

    if(empty($emails)) {
        break;
    }
}

PHP Fiddle sample