三维数组,统计三维里的某个元素个数 [用二维再遍历]
2015-10-26 16:58
369 查看
怎么算出第一个 rule_1 有两个
第一个有2个,第二个 第三个 可能不同
存的时候 ,是双重循环存的,其中有三维i 数组
foreach($shop_list as $key=>$val){ // var_dump($val['shop_id']); // die(); if($m==0){ $info = M ( 'goodsshop' )->where ("id = ".$val['shop_id'])->find(); }else{ $info = M ( 'goodsshop' )->where ("id = ".$val['shopid'])->find(); if($info){ if($info['promotion_status']=='1'){ //1 存在促销且促销激活 $promotion_result = M ( 'goodspromotion' )->where ("promotion_goods= ".$val['shopid']." and state = 1 and rule_style= 1")->select(); //查看促销方式 //商品促销 if($promotion_result){ if(trim($promotion_result[0]['rule_1'])){ $promotion_result = M ( 'goodspromotion' )->order('rule_1')->where ("promotion_goods= ".$val['shopid']." and state = 1 and rule_style= 1")->select(); } if(trim($promotion_result[0]['rule_2'])){ $promotion_result = M ( 'goodspromotion' )->order('rule_2')->where ("promotion_goods= ".$val['shopid']." and state = 1 and rule_style= 1")->select(); } if(trim($promotion_result[0]['rule_3'])){ $promotion_result = M ( 'goodspromotion' )->order('rule_3')->where ("promotion_goods= ".$val['shopid']." and state = 1 and rule_style= 1")->select(); } //var_dump($promotion_result);die(); $count_result = count($promotion_result); for($i=0;$i<$count_result;$i++){ if(trim($promotion_result[$i]['rule_1'])){ $rule_1 = json_decode($promotion_result[$i]['rule_1'],true); $piece = $rule_1['1']; //买几件 $goods_id = $rule_1['2'];//所赠商品id //促销信息$piece $shop_list[$key][$i]['rule_1'] = $rule_1; //是否存在商品促销规则1 $shop_list[$key][$i]['piece'] = $piece; //购买本商品数量 $shop_list[$key][$i]['goods_id'] = $goods_id;//赠送商品id $shop_list[$key][$i]['givenum'] = $rule_1['3']; //赠送商品数量 $giveGood = M ( 'goodsshop' )->where ("id= ".$goods_id)->find(); $shop_list[$key][$i]['giveName'] = $giveGood['goods_name']; $shop_list[$key][$i]['giveGoodImg'] = get_cover_url($giveGood['image']); } /*if(trim($promotion_result['rule_2'])){ $shop_list[$key]['rule_2'] = $rule_2; //是否存在商品促销规则2 //促销信息 $shop_list[$key]['reduce_price'] = $promotion_result['rule_2']; //降多少元 } if(trim($promotion_result['rule_3'])){ $shop_list[$key]['rule_3'] = $rule_3; //是否存在商品促销规则3 //促销信息 $shop_list[$key]['discount'] = $promotion_result['rule_3']; //打多少折 } */ } //var_dump($promotion_result); //$shop_list[$key]['promotion_result'] = $promotion_result; //$this->assign("promotion_result",$promotion_result); $this->assign("count_result",$count_result);//一个商品,有几个商品的促销方案 $this->assign("rule_style1",1);//商品促销 } } }
统计其中一个三维数组,也要用双重循环遍历统计出来
$nn = 0; foreach($shop_list as $key=>&$val){ for($i=0;$i<count($shop_list);$i++){ if($shop_list[$key][$i]['rule_1']){ var_dump("99999"); $nn = $nn + 1; } } $shop_list[$key]['rule_nu'] = $nn; $nn = 0; } var_dump($shop_list);
相关文章推荐
- IOS获取设备的前置摄像头和后置摄像头
- Codeforces 590B Chip 'n Dale Rescue Rangers
- javascript 中call,apply的用法
- ORACLE 日期加减操作
- IO(FileWriter/FileReader)字符流:文件的写入、续写、读
- javascript推荐书籍
- 第七周项目5--排队看病模拟
- 第六周项目1 建立顺序栈“算法库”
- Java 多线程(六) synchronized关键字详解
- Hibernate中inverse="true"的理解
- 项目5 - 计数的模式匹配
- 欢迎使用CSDN-markdown编辑器
- 项目4-广义表算法库及应用
- CentOS epel yum 源配置
- os.system返回值
- struts2中如何设置四大域对象
- C#中M的N次方显示
- Spring知识点总结大全
- node-oracle windows下编译安装
- 深入理解 Java 内存模型(一)- 内存模型介绍