In a foreach()
loop I got a static ID that stays the same but I want it to change every time the foreach()
loop posts a new line.
I have tried a for()
loop and a foreach()
loop, and
in the example below I am using an array but I get the following error:
Array to string conversion
What I want:
id="1",id="2",id="3",id="4",id="5";
My code:
private function recursiveTemplate($templates){
foreach($templates as $key => $template){
$templatenames =array(1,2,3,4,5);
$int=0;
if(is_array($template)){
$this->templateHtml .= '<div class="input-group tempHolder"><span style="width: 155px;" class="input-group-addon" id='.$key.'>'.$key.'</span>';
$this->recursiveTemplate($template);
$this->templateHtml .= '
<button type="button" class="btn2 btn-info" id="addTemplate"><span class="glyphicon glyphicon-plus">
<button type="button" class="btn2 btn-danger" id="deleteTemplate" ><span class="glyphicon glyphicon-minus"></span></span></div>';
}else{
$this->templateHtml .= '<input type="text" class="form-control" id="'.$templatenames .'" name="jezus" aria-describedby="basic-addon3" value="'.$template.'">';
}
}
}
}