2016-07-12 5 views
0

私はできるだけお互いからそれらを作る、ドメインによって電子メールをシャッフルしたいと思います。例:前シャッフルし、別の類似文字列

アレイ:

[email protected][email protected][email protected][email protected][email protected]、email3 @ gmailの。 COM、[email protected][email protected]

それは次のようになる:後

アレイ:

[email protected][email protected][email protected][email protected][email protected][email protected][email protected]、email3 @ gmail私はArrayでそれを行うことができますどのよう.COM

? PHPで任意の例があれば、それは素晴らしいことです。

+0

で必要なものを、あなたはこれまでにしようとしているかを示すことができましたか? – mhatch

+0

は、これはあなたが始めるのに役立つかもしれません:http://php.net/manual/en/array.sorting.php – Katie

答えて

1
<?php 

$emails = array(
    '[email protected]', 
    '[email protected]', 
    '[email protected]', 
    '[email protected]', 
    '[email protected]', 

    '[email protected]', 
    '[email protected]', 
    '[email protected]', 
    '[email protected]', 
    '[email protected]', 

    '[email protected]', 
    '[email protected]', 
    '[email protected]', 
    '[email protected]', 
    '[email protected]', 

    '[email protected]', 
    '[email protected]', 
    '[email protected]', 
    '[email protected]', 
    '[email protected]', 

); 

$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; 
    } 
} 

echo '<pre>'; 
print_r($organized_emails); 
echo '</pre>'; 

申し訳ありませんが、私はちょうど私がPHP Arrays - Sort by Email Address Domain (alternate)

関連する問題