I am creating an Xml like this:
private function setTitle()
{
$rC = $this->data->rC;
$cTimes = array();
$i = 0;
foreach ($rC as $rCKey => $rCValue)
{
$cTimes[] = $rCValue->input_c_start;
}
foreach ($rC as $rCKey => $rCValue)
{
$this->title = $this->titleSetTitles->addChild('title');
$this->title->addAttribute('chapters', $cTimes[$i]);
$i++;
}
}
the output is something like this:
<title chapters="00:01">
...
</title>
<title chapters="00:02">
...
</title>
My question is now how to add in each loop the chapter times so that it looks like this:
<title chapters="00:01">
...
</title>
<title chapters="00:01; 00:02">
...
</title>
<title chapters="00:01; 00:02; 00:03">
...
</title>
Have another variable outside the foreach loop which gets data appended on each iteration.
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++;
}
}
Have a extra variable and use like this:-
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++;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.