$result=array();
目前創(chuàng)新互聯(lián)公司已為上1000家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、綿陽服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計(jì)、南江網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
foreach($hello?as?$array){
$result[$array["uid"]]["order_count"]=$array["order_count"]+(isset($result[$array["uid"]]["order_count"])?$result[$array["uid"]]["order_count"]:0);
$result[$array["uid"]]["count"]=1+(isset($result[$array["uid"]]["count"])?$result[$array["uid"]]["count"]:0);
}
$tmp=array();
foreach($result?as?$key=$array){
$tmp[$key]=$array["order_count"];
}
arsort($tmp);
$newarray=array();
$i=0;
foreach($tmp?as?$key=$array){
$newarray[$i]["uid"]=$key;
$newarray[$i]["order_count"]=$result[$key]["order_count"];
$newarray[$i]["count"]=$result[$key]["count"];
$i++;
}
print_r($newarray);
$aa='[{"id": 0, "num": "2", "name": "產(chǎn)品1", "price": "37", "amount": 74, "zdamount": 100}, {"id": 1, "num": "2", "name": "產(chǎn)品2", "price": "37", "amount": 74, "zdamount": 100}]';
$bb='[{"id": 0, "num": "3", "name": "產(chǎn)品1", "price": "37", "amount": 90, "zdamount": 110}, {"id": 1, "num": "5", "name": "產(chǎn)品2", "price": "37", "amount": 150, "zdamount": 180}]';
$cc='[{"id": 2, "num": "3", "name": "產(chǎn)品3", "price": "37", "amount": 90, "zdamount": 110}, {"id": 1, "num": "5", "name": "產(chǎn)品2", "price": "37", "amount": 150, "zdamount": 180}]';
$j_a = json_decode($aa,1);
$j_b = json_decode($bb,1);
$j_c = json_decode($cc,1);
$arr_list = [$j_a,$j_b,$j_c];//把數(shù)組扔進(jìn)大數(shù)組,這樣可以隨意增加個(gè)數(shù)
$result = [];
foreach ($arr_list as $k=$v) {//第一次循環(huán),把原數(shù)組取出
foreach ($v as $key = $value) {//第二次循環(huán),正式取出數(shù)據(jù)
if (isset($result[$value['id']])) {//如果有此id,則進(jìn)行累加操作
$result[$value['id']]['num'] += $value['num'];
$result[$value['id']]['amount'] += $value['amount'];
$result[$value['id']]['zdamount'] += $value['zdamount'];
} else {//沒有此id則進(jìn)行賦值操作
$result[$value['id']]['id'] = $value['id'];
$result[$value['id']]['price'] = $value['price'];
$result[$value['id']]['name'] = $value['name'];
$result[$value['id']]['num'] = $value['num'];
$result[$value['id']]['amount'] = $value['amount'];
$result[$value['id']]['zdamount'] = $value['zdamount'];
}
}
}
echo json_encode($result,320);//輸出結(jié)果,如果需要序列化鍵值,可以使用array_values($result)
$Data = M('course_card'); // 實(shí)例化Data數(shù)據(jù)對象import('ORG.Util.Page');// 導(dǎo)入分頁類$count = $Data-where($map)-count();// 查詢滿足要求的總記錄數(shù)$Page = new Page($count,1);// 實(shí)例化分頁類 傳入總記錄數(shù)$page-setConfig('header','會(huì)員卡');$Page-setConfig('prev', "上一頁");//上一頁$Page-setConfig('next', '下一頁');//下一頁$Page-setConfig('first', '首頁');//第一頁$Page-setConfig('last', "末頁");//最后一頁$Page - setConfig ( 'theme', '%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%' );// 進(jìn)行分頁數(shù)據(jù)查詢 注意page方法的參數(shù)的前面部分是當(dāng)前的頁數(shù)使用 $_GET[p]獲取$nowPage = isset($_GET['p'])?$_GET['p']:1;$list = $Data-where($map)-page($nowPage.','.$Page-listRows)-select();$show = $Page-show();// 分頁顯示輸出$this-assign('page',$show);// 賦值分頁輸出$this-assign('course_card',$list);// 賦值數(shù)據(jù)集
當(dāng)前文章:數(shù)據(jù)合并計(jì)算php 數(shù)據(jù)合并計(jì)算平均分
標(biāo)題URL:http://vcdvsql.cn/article46/ddoeghg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、做網(wǎng)站、網(wǎng)站營銷、外貿(mào)網(wǎng)站建設(shè)、品牌網(wǎng)站制作、營銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)