模型层获取数据
/** * 获取数据 */
public function getInfos(){
return $this->find()->asArray()->all();
}
public function actionCounts(){
$model = new User; //获取所有数据
$arr = $model->getInfos();
//var_dump($arr);die;
$data = array();
foreach ($arr as $key => $val) {
$str = substr($val[‘u_email‘], strpos($val[‘u_email‘], ‘@‘));//, 20
$str1 = substr($str, 1);
//echo $str1;
$data[$str1][$key] = $str1;
}
//获取数量
foreach ($data as $key => $val) {
echo $key.‘的邮箱‘.count($val).‘个‘;
}
//var_dump($data);die;
/*
//另一种方法
$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 => $val) {
echo $key.‘的邮箱‘.$val.‘个‘;
}
*/
}