The function below facilitates the process of converting an array to a string. Very useful for building SQL insert queries with arrays of data.

<?php
function array2str($array, $pre = '', $pad = '', $sep = ', ')
{
	$str = '';
	if(is_array($array)) {
		if(count($array)) {
			foreach($array as $v) {
				$str .= $pre.$v.$pad.$sep;
			}
			$str = substr($str, 0, -strlen($sep));
		}
	} else {
		$str .= $pre.$array.$pad;
	}

	return $str;
}
?>

Related posts:

  1. Ruby Array to String
  2. PHP Parallel Web Scraper
  3. PHP Simple Profiling Class
  4. PHP Named Parameters
  5. PHP fast, large (megabyte), data transfer between sessions