0

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!

prava
  • 3,916
  • 2
  • 24
  • 35
kacper
  • 370
  • 2
  • 6
  • 13
  • 1
    replace `$check1[] = array('comm'=>$comm->name, 'operations'=>...` with `$check1[$comm->name] = array( 'operations'=>...` (if `$comm->name` is unique, otherwise you have to change `in_array` with `array_search`) – fusion3k Apr 15 '16 at 12:02

1 Answers1

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

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

Naisa purushotham
  • 905
  • 10
  • 18