Trim email list into domain list
- by hanjaya
The function below is part of a script to trim email list from a file into domain list and removes duplicates.
/* define a function that can accept a list of email addresses */
function getUniqueDomains($list) {
// iterate over list, split addresses and add domain part to another array
$domains = array();
foreach ($list as $l) {
$arr = explode("@", $l);
$domains[] = trim($arr[1]);
}
// remove duplicates and return
return array_unique($domains);
}
What does $domains[] = trim($arr[1]); mean? Specifically the $arr[1]. What does [1] mean in this context? How come variable $arr becomes an array variable?