三維數組,統計三維裡的某個元素個數 [用二維再遍曆]

來源:互聯網
上載者:User


怎麼算出第一個 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);




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.