例如,如果电子邮件是Hello@domain.com 我想得到" domain.com" 我想对使用php的表中的几封电子邮件这样做。 我想计算有多少个电子邮件拥有某个域并将其显示为百分比。 例如:Domain1.com:50% Domain2.com:50%
<html >
<head>
<meta charset="utf-8" />
</head>
<body>
<?php
$emails=array("email1@domain1.com","email2@domain2.fr","email3@domain3.com",
"email4@domain4.com");
$domain = explode('@', $emails)[4];
?>
</body>
</html>
&#13;
我想得到:
域名1:25% domain2:25% domain3:25% domain4:25%
答案 0 :(得分:0)
我相信你想要这样的代码
$emails=array("email1@domain1.com","email2@domain2.fr","email3@domain3.com", "email4@domain4.com", "email233@domain4.com");
$results = array();
foreach($emails as $email){
$domain = substr($email, strpos($email, "@") + 1);
$result[$domain] = isset($result[$domain]) ? $result[$domain] + 1 : 1;
}
foreach($result as $key=>$val){
echo $key.": " . 100/array_sum($result)*$val . "<br>";
}