giodamelio giodamelio - 1 month ago 10
PHP Question

PHP Add comma to every item but last one

I have a loop like

foreach ($_GET as $name => $value) {
echo "$value\n";
}


And I want to add a comma in between each item so it ends up like this.

var1, var2, var3


Since I am using
foreach
I have no way to tell what iteration number I am on.

How could I do that?

Answer

Sorry I did not state my question properly. The awnser that worked for me is

implode(', ', $_GET);

Thanks, giodamelio

Comments