<?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)
你能告訴你有什麼到目前爲止已經試過? – mhatch
這可能會幫助你開始:http://php.net/manual/en/array.sorting.php – Katie