2016-07-11 35 views

答えて

0

foreachループの外側にある別の変数を使用して、各繰り返しでデータが追加されるようにします。

private function setTitle() 
{ 
    $rC  = $this->data->rC; 
    $cTimes = array(); 
    $i   = 0; 
    $chapters = ""; 

    foreach ($rC as $rCKey => $rCValue) 
    { 
     $cTimes[] = $rCValue->input_c_start; 
    } 

    foreach ($rC as $rCKey => $rCValue) 
    { 
     $chapters .= $cTimes[$i]."; "; 
     $this->title = $this->titleSetTitles->addChild('title'); 
     $this->title->addAttribute('chapters', substr($chapters, 0, -2)); 
     $i++; 
    } 

} 
+0

作品が、私はあなたがすることを防止した条件になるだろうどのように末尾に空白を取得: '章=" 00:00 :00; 00:10:00; ">' – utdev

+0

@ JohnDoe2 substrで最後の2文字を削除します。私の編集した回答を参照してください – Daan

+0

素晴らしい作品ありがとう – utdev

0

は、余分な変数を持っており、このように使用: -

private function setTitle(){ 
    $rC  = $this->data->rC; 
    $cTimes = array(); 
    $i   = 0; 

    foreach ($rC as $rCKey => $rCValue){ 
     $cTimes[] = $rCValue->input_c_start; 
    } 
    $ncTime = []; 
    foreach ($rC as $rCKey => $rCValue){ 
     $ncTime[] = $cTimes[$i]; 
     $this->title = $this->titleSetTitles->addChild('title'); 
     $this->title->addAttribute('chapters', implode(";", $ncTime)); 
     $i++; 
    } 
} 
関連する問題