Implode in PHP is a convenience function which will convert an array into a string of array elements seperated by $glue. Yesterday I needed a way to easily wrap these elements within quotes (to echo out for a javascript array) and didn’t want to write a foreach loop to do what implode does already.

To wrap the array elements in quotes, or anything for that matter, use the following:

$myArray = array('A', 'B', 'C');

echo "'" . implode("','", $myArray) . "'"; //Displays 'A', 'B', 'C'

echo implode(',', $myArray); //Displays A, B, C