多维数组未定义索引

时间:2016-04-15 11:56:49

标签: php arrays

我正在编写Excel文件生成器。我需要从数据库中获取所有者的名称,然后为所有这些程序列出已完成的程序。当然,我想用计数器显示每个程序一次,该计数器指出每个程序的制作次数。 我尝试使用此代码执行此操作:

// 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']++;
        }
    }
}

不幸的是,我收到了一个未定义的索引:Eden warning&警告:in_array()期望参数2在in_array检查行中是数组警告。我会非常感谢任何帮助。

问候!

1 个答案:

答案 0 :(得分:0)

  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']++;
   }
}

在写入in_array()之前使用is_array($ check1 [$ comm-> name] [' operations'] [' operation'])