[英]Laravel 5.1 Get Input Value
我正在創建一個像這樣的Xml:
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++;
}
}
輸出是這樣的:
<title chapters="00:01">
...
</title>
<title chapters="00:02">
...
</title>
我現在的問題是如何在每個循環中添加章節時間,以便它看起來像這樣:
<title chapters="00:01">
...
</title>
<title chapters="00:01; 00:02">
...
</title>
<title chapters="00:01; 00:02; 00:03">
...
</title>
在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++;
}
}
有一個額外的變量,使用如下: -
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++;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.