How to separate an Array into a comma string inside foreach loop in PHP

Example on how to separate an array into a comma string using PHP. Useful for multiple POST checkboxes.

This is an example on how to separate an array into a comma separated string. I use this for multiple checkboxes POST and add all the checkboxes values into a string. 

POST Example

<input type="checkbox" name="checkbox[]" value="A"> A<br>
<input type="checkbox" name="checkbox[]" value="B"> B<br>
<input type="checkbox" name="checkbox[]" value="C"> C<br>
<input type="checkbox" name="checkbox[]" value="D"> D<br>
<input type="checkbox" name="checkbox[]" value="E"> E<br>

PHP Foreach Array Example

<?php
$comma_string = array();
foreach ($variable as $key => $value) {
	$comma_string[] = $value;
}
$comma_separated = implode(",", $comma_string);
?>

Try it out the array into a comma seperated string. 

Enjoy!