Reputation: 447
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
Upvotes: 1
Views: 107
Reputation: 174957
Using a simple array implosion will do the trick here:
$names[] = "[$name, $surname]";
echo implode(",\n", $names);
Upvotes: 2
Reputation: 2314
$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.
Upvotes: 3