How to count the number of different types of mailboxes through Yii

不言
Release: 2023-04-01 09:36:02
Original
1510 people have browsed it

This article mainly introduces Yii's method of counting the number of different types of mailboxes, involving Yii database queries and string traversal, interception and judgment related operation skills. Friends in need can refer to the following

Examples of this article This article introduces Yii's method of counting the number of different types of mailboxes. Share it with everyone for your reference, the details are as follows:

Rendering:

Controller:

//查询邮箱 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)."个"."
"; }*/ (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."个"."
"; } }
Copy after login

The above is the entire content of this article , I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Yii and CKEditor implement the image upload function

How to use the Bootbox plug-in to implement a custom popup in Yii2 Window

#How to use PHPExcel to export Excel files in Yii2 framework

The above is the detailed content of How to count the number of different types of mailboxes through Yii. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!