Basic question using .= (concatenation assignment) in a loop.
This code produces this PHP error:
Notice: Undefined variable: html
for($i=0; $i<4; $i++) {
$html .= "<h1>Stuff</h1>";
}
If I add an $html = ""; before the loop the error is corrected. Is this the best way to correct this, or am I missing something?
How do I use the .= operator within a loop, and any direction to tutorials to better understand this would be appreciated?
$html = ""outside of the loop else you are attempting to concatenate null with a string which wont work. Thus your correction of adding$html = ""before the loop is correct.""and do the concatenation anyway.