您的位置:首页 > 其它

三维数组,统计三维里的某个元素个数 [用二维再遍历]

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);


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: