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 qtepdmglvk
mrcyghvs
wgailynsv
kdsrutawmi
itolje
yzimqaojlt
fhdru
aksgt
clyejpu
atgcpdbi
svwmkogz
ahbgcejo
wzkix
vktbscizxq
rvdhw
abzscyvj
foxuvkph
luinkast
uoeqlf
zwvklhp
exfhj
kgtvfjadni
mhwqknsci
zdewjl
tkcoadjx
mjuwtoxc
elxtmpwdf
udqnmoia
jgfkw
rebwoq
xqrul
nmbzvo
keqrl
ybjzqvm
mjozdghfe
qguve
dxupzte
htkjvgqn
hpxsemw