本文实例讲述了Yii统计不同类型邮箱数量的方法。分享给大家供大家参考,具体如下:
效果图:
控制器:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
//查询邮箱
public function actionEmail()
{
/* //查询所有邮箱数据(1种)
$arr=Users::find("select * from users")->asArray()->all();
//var_dump($data);die;
$data=array();
//取出邮箱类型
foreach($arr as $key=>$v)
{
$str=substr($v['email'],strpos($v['email'],"@"),50);
$str1=substr($str,1);
$data[$str1][$key]=$str1;
}
//var_dump($data);die;
//获得不同类型邮箱个数
foreach($data as $key=>$v)
{
echo $key."的邮箱有".count($v)."个"."<br>";
}*/
(2种方法)
$arr =Users::find()->select( "email" )->column();
$data = array ();
foreach ( $arr as $key => $v )
{
$pos = strpos ( $v , "@" );
$str = substr ( $v , $pos +1);
$data []= $str ;
}
//var_dump($data);die;
$count = array_count_values ( $data );
// var_dump($count);die;
foreach ( $count as $key => $v )
{
echo $key . "的邮箱有" . $v . "个" . "<br>" ;
}
}
|
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。