douyun1852 2016-04-15 11:56
浏览 41

多维数组未定义索引[重复]

i'm coding an Excel file generator. I need to get name of Owners from database, and then for all of them a list of procedures which was done. Of course I would like to show every procedure only once with a counter which points how many times every procedure had been made. I'm trying to do this with this code:

// to get the list of owners
$this->comms = $this->warehouse->getComms();

foreach($this->comms as $key=>$comm)
{
    // producer / procedure [name] [counter]
    $check1[] = array('comm'=>$comm->name, 'operations'=>array('operation'=>'', 'counter'=>0));

    // to get list of procedures for producer
    $this->operations = $this->warehouse->getCommOperations($comm->id, $this->date_from_search, $this->date_to_search);

    foreach($this->operations as $key=>$operation)
    {
        if(!in_array($operation->dsName, $check1[$comm->name]['operations']['operation']))
        {
            $check1[$comm->name]['operations']=$operation->oService;
            $check1[$comm->name][$operation->oService]['counter']++;
        }
        else
        {
            $check1[$comm->id][$operation->oService]['counter']++;
        }
    }
}

Unfortunately I'm receiving an Undefined index: Eden warning & Warning: in_array() expects parameter 2 to be array warning at in_array check line. I would be very grateful for any help.

Regards!

</div>
  • 写回答

1条回答 默认 最新

  • douzi1991 2016-04-15 12:04
    关注
      foreach($this->operations as $key=>$operation)
      {
        if( is_array($check1[$comm->name]['operations']['operation']))
        {
           if(!in_array($operation->dsName, $check1[$comm->name]['operations']['operation']))
         {
            $check1[$comm->name]['operations']=$operation->oService;
            $check1[$comm->name][$operation->oService]['counter']++;
         }
       }
       else
       {
         $check1[$comm->id][$operation->oService]['counter']++;
       }
    }
    

    before writing in_array() use is_array($check1[$comm->name]['operations']['operation'])

    评论

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装
  • ¥40 复杂的限制性的商函数处理