# 获取家列表 $home_list = Model::home_users()->selectBySql( ‘select h.home_id,h.name from home_users as hu left join home as h on hu.home_id = h.home_id where hu.user_id=?‘ ,[$this->token_info[‘id‘]] ); 输出: [ [‘home_id‘=>‘1‘,‘count‘=>‘31‘], [‘home_id‘=>‘2‘,‘count‘=>‘24‘] ]; # 家的消息数目 $msg = self::readMsg([ ‘user_id‘=>$this->token_info[‘id‘], ‘home_id‘=>$homes, ‘read_type‘=>‘r‘ ]); 返回: [ [‘home_id‘=>‘1‘,‘count‘=>‘31‘], [‘home_id‘=>‘2‘,‘count‘=>‘24‘] ]; $new = array_map(function($h,$m){ return array_merge($h,$m); },$home_list,$msg); 返回: Array ( [0] => Array ( [home_id] => 1 [home_name] => 家1 [count] => 31 ) [1] => Array ( [home_id] => 2 [home_name] => 家2 [count] => 24 ) )
时间: 2024-11-10 22:52:53