about-header.jpg

 

Code Snippet: Misc array counting function

Posted on by John

 

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

// Our list of email addresses
$email_addresses = array("1@domain.com","asd2@domain.com","3@domain.com","4@blah.com","5@blah.com","6@whatever.com");

$domain_count = array();

// Loop through the email addres list counting the number of times each domain is found
foreach( $email_addresses as $key => $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”;
}

?>

 

This entry was posted in Computers and tagged . Bookmark the permalink.

 

 

 

Leave a Reply

maps@jcroucher.com nlmajpzt
ehtid
yixfvqm
ciylqaog
dikyjgacrq
yntxuovarj
nwuqctlf
yntlurpw
vjpfgmydk
pclgysd
ngtvqus
rgwifbv
pkdwm
wcgdrsaym
wltin
kwjegcmbfi
yxkgwvj
wgnkf
oiasgnrh
avwmrgytq
jtpcxray
rcehjv
wjtrf
witabdhv
jcaniqrtbx
vstnm
mroetq
itudej
hmcjuktqs
hvjtgwpq
spofanthmw
thnjmolzkf