2016-04-15 108 views
0

我編碼一個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']++; 
     } 
    } 
} 

不幸的是我收到一個未定義指數:伊甸園警告&警告:in_array()預計參數2是數組中in_array檢查行警告。我會非常感謝任何幫助。

問候!

+1

取代'$ CHECK1 [] =陣列( 'COMM' => $ comm-> name,'operations'=> ...'with'$ check1 [$ comm-> name] = array('operations'=> ...(如果$ comm-> name是唯一的,否則你必須用'array_search'改變'in_array') – fusion3k

回答

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->名] [ '操作'] [ '操作'])