// 选择城市 public function actionCity() { $parameters = ' "requestType": 0 '; $PortData = Interfaces::Connections('city/addresslist', true, Interfaces::Montage($parameters)); $PortData = json_decode($PortData, true); // 热门城市 $model['topList'] = isset($PortData['topList']) ? $PortData['topList']:[]; // 所有城市 $dataList = isset($PortData['topList']) ? $PortData['dataList']:[]; $model['cityList'] = []; if(!empty($dataList)){ foreach ($dataList as $key => $value) { $spell = mobile\models\SpellModel::encode($value['name']); $spell = mb_substr($spell , 0 , 1); if(!empty($spell)) $model['cityList'][$spell][] = $value; } ksort($model['cityList']); //排序 } return $this->render('city', [ 'model' => $model, ]); }
效果图如下:
以上所述是小编给大家介绍的Yii2汉字转拼音类的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章: