用foreach循环去取数据库的值,并合并数组

网友投稿 269 2022-09-13

用foreach循环去取数据库的值,并合并数组

$list = $mTrans->alias('a') ->join('mpp_biz_time b','a.channel_id=b.id') ->field('a.down_sn,a.success_time,a.amount,a.fee,a.acc_no,b.title') ->where(['a.status' => '2']) ->where(['a.member_id' => $member_id]) ->where('a.success_time', 'between', [strtotime($mtime[0]), strtotime($mtime[1] . ' 23:59:59')]) ->order('a.success_time desc') ->select();$list_all = json_decode(json_encode($list,JSON_UNESCAPED_UNICODE ),ture);if (empty($list)) { $this->EchoJson('0', '查询成功');}foreach ($list_all as $k=>$v) { $sn[]=$v['sn']; $acc_no[]=$v['acc_no']; $info[] = Loader::model('admin/Cardbintb') ->field('bank_name,logo') ->where('card_len', strlen($v['acc_no'])) ->where('bin = SUBSTRING(:card_no, 1, bin_len)', ['card_no' => $v['acc_no']]) ->find()->toArray(); if (empty($temp[$v['date']])) { $temp[$v['date']]['total'] = $v['amount']; } else { $temp[$v['date']]['total'] += $v['amount']; } $mtotal += $v['amount'];}$arr = array();foreach($list_all as $k=>$r){ $arr[] = array_merge($r,$info[$k]);}

数组类型$list_all

array(3) { [0]=> array(6) { ["down_sn"]=> string(24) "318031210214511700000823" ["success_time"]=> int(1520821445) ["amount"]=> string(6) "100.00" ["fee"]=> string(4) "4.42" ["acc_no"]=> string(16) "4581231314" ["title"]=> string(20) "银联无卡快捷T1" } [1]=> array(6) { ["down_sn"]=> string(24) "318031210200963800000822" ["success_time"]=> int(1520821269) ["amount"]=> string(6) "100.00" ["fee"]=> string(4) "4.42" ["acc_no"]=> string(16) "4581231314" ["title"]=> string(20) "银联无卡快捷T1" } [2]=> array(6) { ["down_sn"]=> string(24) "318031209553686800000821" ["success_time"]=> int(1520820954) ["amount"]=> string(6) "100.00" ["fee"]=> string(4) "4.42" ["acc_no"]=> string(16) "4581231314" ["title"]=> string(20) "银联无卡快捷T1" }}循环取数据库的值$infoarray(3) { [0]=> array(2) { ["bank_name"]=> string(12) "交通银行" ["logo"]=> int(5) } [1]=> array(2) { ["bank_name"]=> string(12) "交通银行" ["logo"]=> int(5) } [2]=> array(2) { ["bank_name"]=> string(12) "交通银行" ["logo"]=> int(5) }}最终数据合集{ "errcode": 0, "msg": "查询成功", "data": { "list": [ { "down_sn": "318031210214511700000823", "success_time": 1520821445, "amount": "100.00", "fee": "4.42", "acc_no": "4581231314", "title": "银联无卡快捷T1", "bank_name": "交通银行", "logo": 5 }, { "down_sn": "318031210200963800000822", "success_time": 1520821269, "amount": "100.00", "fee": "4.42", "acc_no": "4581231314994443", "title": "银联无卡快捷T1", "bank_name": "交通银行", "logo": 5 }, { "down_sn": "318031209553686800000821", "success_time": 1520820954, "amount": "100.00", "fee": "4.42", "acc_no": "4581231314", "title": "银联无卡快捷T1", "bank_name": "交通银行", "logo": 5 } ], }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Tech Talk · 云技术有话聊 | 带你了解Oracle数据库基础架构及原理
下一篇:年轻群体兴起,品牌如何做年轻化营销呢?
相关文章

 发表评论

暂时没有评论,来抢沙发吧~