Code Snippet: Misc array counting function

A friend wanted some simple code to count the number of times each email address in a list used the same domain.

$value )
{

// Find where the @ symbol is
$start = strpos($value, “@”);

// Get the domain
$domain = substr($value, $start + 1, strlen($value));

// Add to the count
$domain_count[$domain] ++;

}

// Display the domain list with the count
foreach($domain_count as $key => $value )
{
echo “
$key was accessed $value times”;
}

?>

Leave a Reply