I have a smiliar loop:
$names = "
[$name , $surname]
";
echo "$names";
The result:
[Mario,Rossi]
[Aberto,rossi]
[Giovanni,Rossi]
i would this output:
[Mario,Rossi],
[Aberto,rossi],
[Giovanni,Rossi]
Without , in the last result
* I can't know the number of results in the loop
Using a simple array implosion will do the trick here:
$names[] = "[$name, $surname]";
echo implode(",\n", $names);
$names[] = "
[$name , $surname]
";
$comma_sep = implode(",", $names);
echo "<pre>{$comma_sep}</pre>";
The data should be pre-formatted with <pre>
tags if you want to use your line breaks like that.