概述
$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"
}
}
循环取数据库的值$info
array(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
}
],
}
}
最后
以上就是呆萌芹菜为你收集整理的用foreach循环去取数据库的值,并合并数组的全部内容,希望文章能够帮你解决用foreach循环去取数据库的值,并合并数组所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复