PHP数组-按电子邮件地址域排序(备用) [英] PHP Arrays - Sort by Email Address Domain (alternate)

查看:96
本文介绍了PHP数组-按电子邮件地址域排序(备用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要向其发送电子邮件的电子邮件地址数组.

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

我想按备用域名对它们进行排序,所以如果我有30个@ gmail.com,30个@ yahoo.com和30个@ aol.com,则排序将导致一个@ gmail.com,然后是@yahoo.com,然后是@ aol.com,然后又是@ gmail.com,等等.

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.

推荐答案

我可能会这样:

$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小提琴示例

这篇关于PHP数组-按电子邮件地址域排序(备用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆