php 数组读取,PHP读取数组

PHP读取数组

关注:149  答案:3  手机版

解决时间 2021-02-02 03:19

提问者煭揂軟吣

2021-02-01 12:05

array(4) {

[0] => array(4) {

["count"] => array(5) {

[0] => string(1) "1"

[1] => string(1) "0"

[2] => string(1) "0"

[3] => string(1) "0"

[4] => string(1) "0"

}

}

[1] => array(4) {

["count"] => array(5) {

[0] => string(1) "1"

[1] => string(1) "0"

[2] => string(1) "0"

[3] => string(1) "0"

[4] => string(1) "0"

[5] => string(1) "0"

[6] => string(1) "0"

[7] => string(1) "0"

[8] => string(1) "0"

}

}

[2] => array(4) {

["count"] => array(5) {

[0] => string(1) "1"

[1] => string(1) "0"

[2] => string(1) "0"

[3] => string(1) "0"

[4] => string(1) "0"

[5] => string(1) "0"

[6] => string(1) "0"

[7] => string(1) "0"

[8] => string(1) "0"

[9] => string(1) "0"

[10] => string(1) "0"

[11] => string(1) "0"

}

......

每次循环一次都加一次之前的结果,怎么让它不累加,接着显示到下面

foreach ($this->list as $k => $vo) {

$cate[$k]['name']=$vo['name'];

$cate[$k]['id']=$vo['id'];

//产品列表/分类

$co_cate = $M_cp->where("pid=".$vp["id"])->order('id asc')->select();

$cate[$kp]['co_cate']=$co_cate;

$i=0;

foreach($co_cate as $ky=>$val){

$count[] = $M_company->where("status=1 and pid = " . $val['id'])->count();

}

$cate[$kp]['count']=$count;

}

最佳答案

二级知识专家癡情菂尐豬豬

2021-02-01 13:33

foreach ($this->list as $k => $vo) {

$cate[$k]['name']=$vo['name'];

$cate[$k]['id']=$vo['id'];

//产品列表/分类

$co_cate = $M_cp->where("pid=".$vp["id"])->order('id asc')->select();

$cate[$kp]['co_cate']=$co_cate;

$i=0;

$count = array();

foreach($co_cate as $ky=>$val){

$count[] = $M_company->where("status=1 and pid = " . $val['id'])->count();

}

$cate[$kp]['count']=$count;

}把count 数组每次都初始化

全部回答

1楼試著忘記壹切

2021-02-01 14:43

上面的方法可以打印输出,json_decode($tdata)输出的结果是一个对应,而json_decode($tdata,true)输出的是一个数组

2楼凊搽蒗囝

2021-02-01 13:40

$count,使用之前先给他重置一下喽!这样就不会携带原有的值了!

我要举报

如以上信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!

推荐资讯

大家都在看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值