thinkphp中统计二维数组里面的某个值输出个数

作者:袖梨 2022-06-25

如下数据

 代码如下 复制代码

array(6) {
  [0] => array(16) {
    ["id"] => string(4) "3942"
    ["name"] => string(9) "shanmao.s"
    ["dctime"] => string(10) "1347465600"
    ["daytype"] => string(6) "晚餐"
    ["shop"] => string(17) "宝嘟嘟 Baodudu"
    ["food"] => string(12) "凉拌豆皮"
    ["tel"] => string(7) "2227019"
    ["price"] => string(1) "7"
    ["pack"] => string(0) ""
    ["many"] => string(1) "1"
    ["total"] => string(1) "7"
    ["exp"] => string(14) "不是加班, "
    ["note"] => NULL
    ["orderip"] => string(9) "127.0.0.1"
    ["ordertime"] => string(10) "1347509101"
    ["sid"] => string(3) "153"
  }
  [1] => array(16) {
    ["id"] => string(4) "3941"
    ["name"] => string(5) "admin"
    ["dctime"] => string(10) "1347465600"
    ["daytype"] => string(6) "午餐"
    ["shop"] => string(12) "一鸣瓦罐"
    ["food"] => string(6) "煨饭"
    ["tel"] => string(11) "15859253924"
    ["price"] => string(1) "1"
    ["pack"] => string(1) "0"
    ["many"] => string(1) "1"
    ["total"] => string(1) "1"
    ["exp"] => string(2) ", "
    ["note"] => NULL
    ["orderip"] => string(9) "127.0.0.1"
    ["ordertime"] => string(10) "1347501557"
    ["sid"] => string(3) "195"
  }
  [2] => array(16) {
    ["id"] => string(4) "3940"
    ["name"] => string(5) "admin"
    ["dctime"] => string(10) "1347465600"
    ["daytype"] => string(6) "午餐"
    ["shop"] => string(20) "新斯利美 Silimei"
    ["food"] => string(22) "鲜橙汁 orange juice"
    ["tel"] => string(7) "2202926"
    ["price"] => string(2) "12"
    ["pack"] => string(0) ""
    ["many"] => string(1) "1"
    ["total"] => string(2) "12"
    ["exp"] => string(2) ", "
    ["note"] => NULL
    ["orderip"] => string(9) "127.0.0.1"
    ["ordertime"] => string(10) "1347501541"
    ["sid"] => string(3) "137"
  }
  [3] => array(16) {
    ["id"] => string(4) "3939"
    ["name"] => string(5) "admin"
    ["dctime"] => string(10) "1347465600"
    ["daytype"] => string(6) "午餐"
    ["shop"] => string(21) "福品堂土楼小吃"
    ["food"] => string(9) "拌青菜"
    ["tel"] => string(7) "2027386"
    ["price"] => string(1) "3"
    ["pack"] => string(3) "0.5"
    ["many"] => string(1) "1"
    ["total"] => string(3) "3.5"
    ["exp"] => string(2) ", "
    ["note"] => NULL
    ["orderip"] => string(9) "127.0.0.1"
    ["ordertime"] => string(10) "1347499513"
    ["sid"] => string(3) "185"
  }
  [4] => array(16) {
    ["id"] => string(4) "3938"
    ["name"] => string(5) "admin"
    ["dctime"] => string(10) "1347465600"
    ["daytype"] => string(6) "午餐"
    ["shop"] => string(20) "新斯利美 Silimei"
    ["food"] => string(27) "珍珠奶茶 pearl milk tea"
    ["tel"] => string(7) "2202926"
    ["price"] => string(1) "6"
    ["pack"] => string(0) ""
    ["many"] => string(1) "1"
    ["total"] => string(1) "6"
    ["exp"] => string(2) ", "
    ["note"] => NULL
    ["orderip"] => string(9) "127.0.0.1"
    ["ordertime"] => string(10) "1347499501"
    ["sid"] => string(3) "137"
  }
  [5] => array(16) {
    ["id"] => string(4) "3937"
    ["name"] => string(5) "admin"
    ["dctime"] => string(10) "1347465600"
    ["daytype"] => string(6) "午餐"
    ["shop"] => string(20) "新斯利美 Silimei"
    ["food"] => string(27) "珍珠奶茶 pearl milk tea"
    ["tel"] => string(7) "2202926"
    ["price"] => string(1) "6"
    ["pack"] => string(0) ""
    ["many"] => string(1) "1"
    ["total"] => string(1) "6"
    ["exp"] => string(2) ", "
    ["note"] => NULL
    ["orderip"] => string(9) "127.0.0.1"
    ["ordertime"] => string(10) "1347499489"
    ["sid"] => string(3) "137"
  }
}

php代码

 代码如下 复制代码

$olist=M()->query("SELECT `order`.*,`shop`.id as sid from `order` inner join `shop` on `shop`.shop = `order`.shop WHERE FROM_UNIXTIME(dctime,'%Y%m%d')=$jint ORDER BY id desc LIMIT 40");
        dump($olist);
        $this->assign('zdlist',$zdlist);
         foreach($olist as $key => $val){
            $vshop[] = $val['shop'];//找出每个店铺赋值到$vshop       
         } 
         $ac= array_count_values($vshop); //统计个数
        $this->assign('ac',$ac);//输出统计
        $this->assign('zuijin',$olist);//输出列表

模板文件

 代码如下 复制代码

有人点了:【{$vo.shop}】($shop = $vo['shop']; echo $ac[$shop]人点这家) 的{$vo.food}

核心的一句

 代码如下 复制代码

$shop = $vo['shop']; echo $ac[$shop]

相关文章

精彩推荐